美文网首页
laravel4.2 command的使用

laravel4.2 command的使用

作者: 木十2036 | 来源:发表于2017-06-21 23:15 被阅读222次

1、php artisan command:make TestCommand
执行完后,会在 app/commands 文件夹中生成 TopicMakeExcerptCommand.php 文件
2、注册命令
在 app/start/artisan.php 文件里面, 添加以下
Artisan::add(new TestCommand);

<?php

use Illuminate\Console\Command;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputArgument;

class TestCommand extends Command {

    /**
     * The console command name.
     *
     * @var string
     */
    protected $name = 'test';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Command test.';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function fire()
    {
        $res = DB::table('person')->get();
        print_r($res);
    }

    /**
     * Get the console command arguments.
     *
     * @return array
     */
    protected function getArguments()
    {
        return array(
            // array('example', 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),
        );
    }

}

相关文章

网友评论

      本文标题:laravel4.2 command的使用

      本文链接:https://www.haomeiwen.com/subject/wckxcxtx.html