I started using CakePHP (1.2) a few months ago to add small features to an enterprise application, and I'm not very familiar with it.
We then test locally on the development server before merging with the production server.
I want the controller action to be called every hour from the fact that I suggested that this is the best way to do this through my research, the cron task.
Attempt 1
After reading this data
http://bakery.cakephp.org/articles/mathew_attlee/2006/12/05/calling-controller-actions-from-cron-and-the-command-line
http://book.cakephp.org/1.2/en/view/110/Creating-Shells-Tasks
I could implement something without errors, but the action fails.
Based on these examples, I added the cron_dispatcher.php file to the application directory (not app / webroot), and then ran this command from the dir application
php cron_dispatcher.php / controller / action / param
Nothing still happens, but it works fine when I call it through a URL.
Attempt 2
I tried to create a shell (email.php) that would trigger an action in / app / vendors / shells /.
<?php class EmailShell extends Shell { public function main() { $this->out('Test'); } } ?>
This successfully displays Test in the console using
cake email
but then I can not find how to trigger a controller action. I tried
$ this-> requestAction ('/ controller / action');
I also tried to make a call from a function other than the main one in the shell.
I tried to include the controller in the $ uses variable, as with the model, but this did not work (and it does not make sense, I think)
I donโt think creating a task is a solution, because I donโt want to duplicate the sendEmails function, so Iโm looking for a way to just call the controller action from the shell or something else!
There is probably some theory I'm missing, thanks
Decision
I moved some methods from the controller to the model, and I was able to call them from the shell.
App::import('Component', 'Email'); class SendMemosShell extends Shell { var $uses = array( 'Memo', ); public function main() { } public function sendEmails () { $this->Email =& new EmailComponent(null); $memoList = $this->Memo->getMemos();
This link helped http://book.cakephp.org/2.0/en/console-and-shells/cron-jobs.html
edit: clarified some of the information and added a solution