Reputation: 93
I am new to Yii2 and web development. Could you please explain me how to launch Yii2 console, because it's not clear from the documentation: http://www.yiiframework.com/doc-2.0/guide-tutorial-console.html. I understood that there is a yii console file where I can configure some commands, but how to I actually launch it?
Upvotes: 0
Views: 1263
Reputation: 3990
Run in your terminal your_project_path/yii controller/action [options]
(make sure yii
has execute permissions).
Substitute controller/action
by some already shipped commands (i.e.: migrate/up
), or write your own inside the console application.
Upvotes: 1
Reputation: 714
it's so easy to use , if you don't access SSH you wont lunch console .
go to your yii directory where you can find a file named YII ( without any extaion )
RUN that with php command
php yii yourconntroller-name/your-action-name
before that you have to create a contorller and action in it
it's a simple sample :
<?php
namespace console\controllers;
use yii\console\Controller;
use common\models\Post;
/**
* Test controller
*/
class TestController extends Controller {
public function actionIndex() {
echo date( 'Y-m-d H:i:s');
$p = Post::find()->where('status=0 AND auto_publish_date IS NOT NULL AND auto_publish_date < NOW( ) ')->all();
foreach($p as $post){
echo $post->id."\n";
$post->status=1;
date_default_timezone_set('Asia/Tehran');
$post->time = date( 'Y-m-d H:i:s');
$post->save();
}
echo "....\n".count($p)." posts has been published ...\n";
}
}
Upvotes: 2