You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
For connection establishment, copy contents of /protected/config/main.php to /protected/config/console.php with DB connection & other information
Comment this line //'defaultController' => 'controller_name' (if_exists)
Then create a file inside commands folder with any name you wish as per this convention yournameCommand.php e.g /protected/commands/SiteCommand.php
Paste below code in SiteCommand.php File which extends from CConsoleCommand and have name SiteCommand
<?php
// it will run default if not action defined in the on the SiteCommand class
class SiteCommand extends CConsoleCommand
{
public function run($args)
{
echo 'Hello yii friends from command line';
}
}
?>
Then open cmd.
Go to cd \path\protected>yiic then press Enter Key.
The cmd will show you the available commands names.
Run ./yiic site and then press Enter Key
It will Show your output "Hello yii friends from command line".
For user defined controller action
Follow above steps 1,2,3 and copy below code
Follow above steps 5,6,7
Finally run this command to show output $ ./yiic MyController MyActionName
<?php
class MyControllerCommand extends CConsoleCommand
{
public function actionMyActionName(){
echo 'Hello yii friend from controller action';
}
}
?>
It will Show your output "Hello yii friend from controller action".