1. In /protected/commands, add a file GoCommand.php with this content:
<?php class GoCommand extends CConsoleCommand { public function run($args) { echo 'Hello, world'; } } ?>2. If you want to use your models, components and db connection, in /protected/config/console.php, copy over your 'import' and 'components' arrays from your main.config:
<?php // This is the configuration for yiic console application. return array( 'basePath'=>dirname(__FILE__).DIRECTORY_SEPARATOR.'..', 'name'=>'My Console Application', // autoloading model and component classes 'import'=>array( 'application.models.*', 'application.components.*', ), // application components 'components'=>array( 'db'=>array( 'connectionString' => 'mysql:host=localhost;dbname=my_db', 'emulatePrepare' => true, 'username' => 'root', 'password' => 'password', 'charset' => 'utf8', 'tablePrefix'=>'tbl_', ), ), );3. then using the command prompt (cmd.exe in Windows), change directories to the protected folder of your web app, and type
yiic Goand it should run your command.
You can use your models and components and most parts of the Yii framework, but web application stuff won't work, like sessions.
4. In Windows, you can use Task Scheduler to run the PHP file using the command line. Here's an article on how to do it:
http://www.devx.com/DevX/Article/39900/1763/page/3
Don't work for me :(
ReplyDeletei am already generate a action in controller that generate xml file i want access that url from command prompt?ple tell as soon as possible...
ReplyDeletehow to execute url in your yii console?
ReplyDeleteecho Yii::app()->createAbsoluteUrl('cron/run');
Thank you the post, that is what i am looking for. I will try it :)
ReplyDeletethat's sound useful for me, thank you
ReplyDeletethat's sound useful for me, thank you
ReplyDeleteThanks you! I can it :-)
ReplyDeleteThank for share . i can it . thanks thanks :d
ReplyDeleteThanks you the post :)
ReplyDeletethanks you
ReplyDeleteecho Yii::app()->createAbsoluteUrl('cron/run');
Thanks you the post :)
ReplyDeletevery good !!!
see you gain
It looks so simple, but it wont work for me. I did everything you said to do, and yiic cant see my command. I get this output:
ReplyDeleteYii command runner (based on Yii v1.1.12)
Usage: C:\Websites\[site path]\yiiframework\yiic [parameters...]
The following commands are available:
- message
- migrate
- shell
- webapp
To see individual command help, use the following:
C:\Websites\[site path]\yiiframework\yiic help
I have been scouring google for hours and i cant find a solution! Anyone have any suggestions?
I figured out why yiic would not see my commands.....someone on my project had removed the yiic file, the yiic.php and the yiic.bat from the protected directory, so it was pulling those files from the framework directory instead - which was putting the base bath as the wrong path, and not loading the config file.
ReplyDeletemake sure those 3 files are in your protected dir.
i just wasted 3 hours figuring that out.
http://www.devx.com/DevX/Article/39900/1763/page/3 the webpage is not available...
ReplyDeleteIt shows Page Not found error
Yii command runner (based on Yii v1.1.12)
ReplyDeleteUsage: C:\Websites\[site path]\yiiframework\yiic [parameters...]
thanks you
ReplyDeleteecho Yii::app()->createAbsoluteUrl('cron/run');
so i don't understand, so sad
ReplyDeleteYii command runner (based on Yii v1.1.12)
ReplyDeleteUsage: C:\Websites\[site path]\yiiframework\yiic [parameters...]