Monday, January 27, 2014

Cake console shell error - not able to see App

Hi All,

I am new to the cake console and especially to creating a shell to run in/on it. The research I have done says it should be possible to call App from the shell and the examples I have seen use code like the below to do so.

<?php
App::uses('AppShell', 'Console/Command');
App::uses('ComponentCollection', 'Controller');
App::uses('Controller', 'Controller')
App::uses('ManageMailComponent', 'Controller/Component');

class NikkiShell extends Shell {
   public function execute() {
       $this->out("Processing...\n");
       $collection = new ComponentCollection();
       $this->MMail = new ManageMailComponent($collection);
       $controller = new Controller();
       $this->MMail->initialize($controller);

       $this->MMail->doMailCall();
       $this->out("Complete\n");
   }
}
?>

But, when I run this I get a syntax error stating: unexpected 'App' (T_STRING) in <my shell file>

Or, if I try this other suggested method (sorry, can't remember where I found this as a suggested method):

<?php
class MailShell extends AppShell {
    var $uses = array('telemetryData');

   public function main() {
       $this->out('Hello world.');
   }
}
?>

Then I get this error:
Fatal error: Class 'AppModel' not found in <longpath>\lib\Cake\Utility\ClassRegistry.php

And here is some more possibly relevant fun info:

There are 2 Console folders - app/Console and lib/Cake/Console - I am sure this is correct, but on mine, no matter where I run the cake.bat file it always calls the lib/Cake/Console/Command folder for the shell file and never the app/Console/Command folder. Not sure if this is at all relelvant, but thought it would be worth mentioning. - Yes, I do have path environment variable set and have tried pointing at each directory in turn.

I also had to copy the cake.bat file from a new zipped version of cake into the two Console folders as my copy did not have it. Not sure why, but think it might have been version control related or something along those lines. Anyway, there may have been a slight adjustment in the version of Cake (mayby a .1 or .2) but I'm not sure as my origional files were on an old machine and not accessible, so I couldn't compare versions (I am sure there is a way to check in the files themselves, but I am lame and couldn't figure it out).
So I do know the project is cakephp 2.something at least, but there is a chance that my cake.bat file is from a very slightly newer version.

That's pretty much it.
Has anyone had this issue?
Has anyone successfully called their App from a shell file?
Am I being a complete moron? (Occam's Razor favours this answer)

Thanks in advance,
Nikki

--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP
 
---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/groups/opt_out.

No comments: