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进程D状态_转
Linux进程状态:S (TASK_INTERRUPTIBLE),可中断的睡眠状态. 处于这个状态的进程因为等待某某事件的发生(比如等待socket连接.等待信号量),而被挂起.这些进程的task_s ...
- IPC之信号量
无名信号量 POSIX标准提出了有名信号量和无名信号量来同步进程和线程,而linux(2.6以前)只实现了无名信号量. sem_overview中有详细介绍:man 7 sem_overview. S ...
- httpClient使用中报错org.apache.commons.httpclient.HttpMethodBase - Going to buffer response body of large or unknown size.
在使用HttpClient发送请求,使用httpMethod.getResponseBodyAsString();时当返回值过大时会报错: org.apache.commons.httpclient. ...
- nginx 为什么要反向代理 影藏后端 高效连接(给nginx,他自己返回) 端口冲突解决 多个服务
nginx 为什么要反向代理 影藏后端 高效连接(给nginx,他自己返回) 端口冲突解决 多个服务 单机使用反向代理可以根据不同url匹配到不同站点 rsync 的工作原理和应用实例 ...
- 微信小程序3 - 对象的合并
ES6中 Object.assign方法用于对象的合并,将源对象( source )的所有可枚举属性,复制到目标对象( target ). 限制: 只是浅拷贝, 即 内部对象 不会拷贝,只是 引用 ...
- 成功抓取douban 所有电影
之前爬了250,想爬所有的电影 Rule(LinkExtractor(allow=(r'https://movie.douban.com/subject/\d+')), callback=" ...
- android启动界面
/** * 应用程序启动类:显示欢迎界面并跳转到主界面 * <a href="http://my.oschina.net/arthor" target="_bl ...
- Attention Mechanism
首先介绍Attention机制: 转自:http://blog.csdn.net/malefactor/article/details/50550211 上面讲的是Soft Attention Mod ...
- 【Python】求素数-未经过任何优化
print 'Find prime number smaller then input number \n' print 'Please input a number:' import time nu ...
- gcc/g++ 实战之编译的四个过程
gcc和g++分别是GNU(一个开源组织)的c&c++编译器 对于.c后缀的文件,gcc把它当做是C程序,g++当做是C++程序:对于.cpp后缀的文件,gcc和g++都会当做c++程序. ...