yii如何使用php-cli模式执行

我看了下yii例子都是做web应用的,

直接php test.php这种模式具体有哪些不同,无处入手,谁能给最简单的例子,谢谢了

已经解决~

感觉就是yii Console Applications例子说的

http://www.yiiframework.com/doc/guide/zh_cn/topics.console

执行的时候报错

php index.php EmailCommand abc

?exception ‘CException’ with message ‘The command path “/path/trunk/common/commands” is not a valid directory.’ in /var/www/vhosts/yii/framework/console/CConsoleApplication.php:144

Stack trace:

请参阅php手册

搞好了 原来是配置文件部分没加array

改成如下就好了。

‘commandMap’=> array(‘EmailCommand’),

简单流程就是local.php里面添加

return array(

'basePath'=>dirname(__FILE__).DIRECTORY_SEPARATOR.'..',





 'commandMap'=> array('EmailCommand'),

…)

然后写一个class到指定的目录比如我得是

../common/commands

下,然后把

class EmailCommand extends CConsoleCommand

{

public function run($args)


{

var_dump($args);

    $receiver=$args[0];


    // send email to $receiver


}

}

加进去就可以了

执行得时候用php test.php Email abc 123,看到结果就对了,然后在这个类里面封装业务就可以了。

[fireod@linux09 test]$ php command.php Email abc 123

array(2) {

[0]=>

string(3) "abc"

[1]=>

string(3) "123"

}