-1

I'm completly lost. I followed several tutorials about cron and Yii but all failed ( Tuto 1 - phpdoc-crontab, Tuto 2 ).

Furthermore, the project is not mine and protected folder does not exist..

I would like to execute an UPDATE in my DB, after controls, every 10 minutes.

I already know how to create a cron but.. Don't really know how to deal with Yii.

I need connection to DB and access to models..

Thanks for your help

UPDATED :

Thanks to @crafter's response I'm able to execute yiic AutoCron but I get an error :

"PHP Error[2]: include(User.php): failed to open stream: No such file or directory "

I can't use config/console.php because the project does not respect standard structure.

How can I import all models in order to avoid this error ?

I got the exactly same issue as this post : Yii - How to access to model and call action in yiic !

I also have a cronconfig.php (Into which I import models) No response yet..

Community
  • 1
  • 1
Delphine
  • 861
  • 8
  • 21
  • I cannot believe you searched enough. I took the tags you entered and searched on google and the first hit was http://www.yiiframework.com/wiki/91/implementing-cron-jobs-with-yii/ – crafter Oct 29 '14 at 05:37

1 Answers1

0

Refer to the WIKI post

http://www.yiiframework.com/wiki/91/implementing-cron-jobs-with-yii/

You need to create a class in protected/commands which extends CConsoleCommand

class TestCommand extends CConsoleCommand {
    public function run($args) {
       // You can use your Yii library here, for example
       $userModel = User::model()->findByPK(1);
       $userModel->active = 'N';
       $userModel->save();
    }
}

You can run the command using the yiic tool, for example for the protected/commands/myCronJobCommand.php file.

$ cd protected    
$ ./yiic myCronJob
crafter
  • 6,246
  • 1
  • 34
  • 46
  • First, I said I haven't protected folder.. That's why I did not know where to place files. I've thought in library/Yii/cli/commands where DocCommand.php, for example, is too. Your code example is not the same as in the tuto you mention. I tried but when I run yiic AutoCron it runs "run" method. Should I create as much files as I have method to execute ? Furthermore, I would like to get User Model but.. "PHP Error[2]: include(User.php): failed to open stream: No such file or directory ". Even with my previous test, yes I did it, I got the same issue. I'm new in Yii and it's not MY code. – Delphine Oct 29 '14 at 08:47
  • @Delphine, You asked how to update your model in a Cron job, I showed you, If you are using some extension that uses a non-standard method then you should not have tagged the question with Yii. When you run yiic AutoCron, it WILL run the run() method in AutoCronCommand.php - check the link I provides, it is explained there. Please update your original question with these details so it is not hidden in the comment. – crafter Oct 29 '14 at 12:25