laravel command命令行
生成类
为了创建一个新命令,你可以使用Artisan中的 command:make 命令生成一个骨架作为你的起点:
生成一个命令类
php artisan command:make FooCommand
默认情况下,生成的类文件被存放在 app/commands 目录下,同时你也可以指定自定义目录和命名空间:
php artisan command:make FooCommand --path=app/classes --namespace=Classes
注册命令
一旦你的命令完成后,你需要使用 Artisan 进行注册,这样才能够被使用。这通常在 app/start/artisan.php文件中完成。在这个文件中,你可以使用 Artisan::add 函数注册命令:
注册一个 Artisan 命令
Artisan::add(new CustomCommand);
如果你的命令在应用程序的 IoC 容器 中注册,你可以使用 Artisan::resolve 函数使它对 Artisan 可用:
注册一个在 IoC 容器中的命令
Artisan::resolve('binding.name');
一个发邮件样例:
<?php use Illuminate\Console\Command;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputArgument; class SendMailCommand extends Command { /**
* The console command name.
*
* @var string
*/
protected $name = 'SendMailCommand:sendMail';//命令名,命令行调用使用php artisian 这里的$name值 /**
* The console command description.
*
* @var string
*/
protected $description = 'send mail.'; /**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
} /**
* Execute the console command.
*
* @return mixed
*/
public function fire()
{
//
$command=" C:/sendEmail -f from.sina.com -t to@qq.com -s smtp.sina.com -xu username -xp pasword -u test ";
$message=$this->argument('message');
$str="$command -m $message ";
$this->info($str);
system($str);
$this->info("It's Done, have a good day."); } /**
* Get the console command arguments.
*
* @return array
*/
protected function getArguments()
{
return array(
array('message', InputArgument::REQUIRED, 'An example argument.'),
);
} /**
* Get the console command options.
*
* @return array
*/
protected function getOptions()
{
return array(
//array('example', null, InputOption::VALUE_OPTIONAL, 'An example option.', null),
);
} }
运行:
php artisan commanname argx --option=bar --option=baz
参考:
http://www.golaravel.com/docs/4.0/commands/
http://www.sitepoint.com/create-laravel-css-minify-command/
laravel command命令行的更多相关文章
- 1)实际时间(real time): 从command命令行开始执行到运行终止的消逝时间; 2)用户CPU时间(user CPU time): 命令执行完成花费的用户CPU时间,即命令在用户态中执行时间总和; 3)系统CPU时间(system CPU time): 命令执行完成花费的系统CPU时
1)实际时间(real time): 从command命令行开始执行到运行终止的消逝时间: 2)用户CPU时间(user CPU time): 命令执行完成花费的用户CPU时间,即命令在用户态中执行时 ...
- Laravel常用命令行中文版
1.生成控制器 php artisan make:controller ArticleController 对应的会在app/http/controllers下面生成ArticleController ...
- windows下安装python、环境设置、多python版本的切换、pyserial与多版本python安装、windows命令行下切换目录
1.windows下安装python 官网下载安装即可 2.安装后的环境设置 我的电脑--属性--高级--设置path的地方添加python安装目录,如C:\Python27;C:\Python33 ...
- java命令行导出、导入sql文件
@IocBean public class SqlCommandModel{ //用户名 @Inject("java:$conf.get('jdbc.username')") pr ...
- Mac系统终端命令行不执行命令 总出现command not found解决方法
配置过安卓开发环境,改过bash_profile这个文件,最后不知怎么的只有cd命令能执行,我猜测可能修改bash_profile文件后没有保存 导致的 保存命令是: source .bas ...
- Qt_Window@Qt Command Prompt从命令行创建工程
#include <QApplication> #include <QLabel> int main(int argc, char *argv[]) { QApplicatio ...
- MAC 命令行工具(Command Line Tools)安装
不过升级后安装命令行工具(Command Line Tools)时发现官网没有clt的下载安装包了,原来改了,使用命令在线安装. 打开终端,输入命令:xcode-select --install 选择 ...
- mac下使用命令行打包出现bash gradle command not found的解决方案
命令行打包的时候出现 bash gradle command not found这个问题,主要是因为gradle环境丢失.需要重新配置gradle的环境变量. 1. gradle路径的查找 然后gra ...
- Windows命令行command的Shell命令详细解析和语法
CMD命令大全及详细解释和语法 Microsoft Windows XP [版本 5.1.2600] 有关某个命令的详细信息,请键入 HELP 命令名 ASSOC 显示或修改文件扩展名关联. A ...
随机推荐
- Linux环境下连接Mssql 2008
首先,Linux环境装个驱动:Microsoft® SQL Server® ODBC Driver 1.0 for Linuxhttps://www.microsoft.com/en-us/downl ...
- Tuning 14 Using Oracle Data Storage Structures Efficiently
90% 是Heap table Cluster 集群表, index-organized table: 就是把索引和表 和二为一了. partitioned table:表非常大, 逻辑上是一个大表, ...
- Apollo 刨析:简介
Apollo是配置在IIS服务器上的一个Web站点,它使用了.NET4.0和ASP.Net的技术. 代码是C#编写的.是基于ASP.NET MVC3的Web开发框架上编写的一个应用. 它使用到了N ...
- SpringMVC整合Shiro(配解释)
第一步:配置web.xml ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 <!-- 配置Shiro过滤器,先让Shiro过滤系统接收到的请求 --> ...
- python import错误 SyntaxError: invalid syntax
导入一个叫service-listener.py的文件是一直遇到错误: SyntaxError: invalid syntax 单独运行service-listener这个文件时,没有问题,只是不能被 ...
- php在linux中执行外部命令
目录:一.PHP中调用外部命令介绍二.关于安全问题三.关于超时问题四.关于PHP运行linux环境中命令出现的问题 一.PHP中调用外部命令介绍在PHP中调用外部命令,可以用,1>调用专门函数. ...
- 微信 openId
摘要 关于微信开发的话题,例子确实已经有不少,但大部分都是人云亦云,很多小细节或者需要注意的地方却大多没有讲清楚,这令很多刚开始开发的人感觉大很迷茫.而我今天要说的话题,主要着眼于两个方面. 一:如何 ...
- Otter双A同步搭建入门教程
1.准备阶段 1.1 环境 虚拟机A :192.168.0.130 虚拟机B :192.168.0.131 系统:Ubuntu 16.04 LTS JRE:OpenJDK 1.8.0_151(A.B都 ...
- django用户认证系统——登录4
用户已经能够在我们的网站注册了,注册就是为了登录,接下来我们为用户提供登录功能.和注册不同的是,Django 已经为我们写好了登录功能的全部代码,我们不必像之前处理注册流程那样费劲了.只需几分钟的简单 ...
- Mysql event时间触发器,实现定时修改某些符合某一条件的某一字段
我最近做项目遇到一个问题就是数据库的的订单需要定时检查自己的订单状态,如果到了endtime字段的时间订单状态还是2,就将订单状态修改为4 在网上找到类似的解决方法. 定时的关键是要结合mysql的某 ...