生成类

为了创建一个新命令,你可以使用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/

https://phphub.org/topics/34

http://www.sitepoint.com/create-laravel-css-minify-command/

最新文章

  1. EasyUI树和Ztree树冲突问题
  2. MSDTC故障排除,DTCTester用法 (二)
  3. 【学】jQuery的源码思路6——增加each,animaion,ajax以及插件机制
  4. Hadoop集群管理之配置文件
  5. 前端自动化神器gulp使用记录
  6. iOS-scrollview及其子类适配iOS7
  7. 排列的Java递归语言实现
  8. C# - 通过自定义注解反射生成SQL语句[转]
  9. Unity安装问题
  10. 2,返回Json
  11. MVC设计思想
  12. C# Global定时执行Global文件aTimer处理
  13. ERROR 1045 (28000): Access denied for user &#39;mysql&#39;@&#39;localhost&#39; (using password: YES
  14. Leetcode : eImplement strStr
  15. 自学Aruba4.1-Aruba开机初始化
  16. Provided id of the wrong type for class pojo.Books. Expected: class java.lang.Integer, got class java.lang.Long
  17. iOS开发之--解决 swap file “*.swp”already exists!问题
  18. Git-简单的利用SourceTree提交代码
  19. 从kepware定时取web api内容
  20. Windows下编译打包Spice PC客户端

热门文章

  1. esp8266必备知识
  2. 最短路中部分点仅仅能从中随意选取K个问题
  3. windows连接远程打印机
  4. asscert断言的几种方法
  5. 下载VMware
  6. 如何让VS检查函数和类Comment的添加情况
  7. xmpp muc 群聊协议 1
  8. CodeForces 668B Little Artem and Dance
  9. spring + quartz 定时
  10. Centos6.5 DNS配置