Cakebaker, at cakebaker.42dh.com, has resolved this issue for me
(http://cakebaker.42dh.com/2007/05/07/writing-a-custom-cakephp-console-
script/).  In case anyone else runs into this same issue some day, the
resolution is that my code was missing the controller initialization
after the instantiation:

$this->CitiesController = new CitiesController();
$this->CitiesController->constructClasses();

The cake manual has a page mentioning this under Developing With
CakePHP > Controllers > Controller Methods > Other Useful Methods >
constructClasses (http://book.cakephp.org/view/429/constructClasses).

For anyone who hasn't carefully perused the more basic sections in the
cake manual like Controllers, Models, and Views since v1, this
requirement when using the console can be pretty easy to miss.  I'm
adding a comment to the manual in the console section and hopefully
someone sees fit to expand on it as part of the console section
proper.

chris

On Nov 19, 3:26 pm, calzone <[EMAIL PROTECTED]> wrote:
> Sorry if this is a likely stupid question, but I can't seem to find
> the answer anywhere. Searching for CakePHP console examples outside of
> using it for ACL and baking seems mighty thin on google.  Maybe I'm
> overlooking something that should be obvious?
>
> The Backstory:
> I have cakephp doing some intensive data processing using many
> different actions in a specified sequence and even with pagination to
> avoid timeouts.
>
> I decided to try to automate this by setting up a cake shell function
> to go through all of the steps and then I can just invoke the magic
> from the command line and output report results into a file. I
> followed the example from this 
> page:http://twit88.com/blog/2008/02/14/php-writing-a-console-program-in-ca...
>
> The Issue:
> What is happening when I try to invoke a controller action from within
> a shell function is that I get the following error (this only happens
> when the controller action I invoke has within a call to a model
> method --as most controller actions are wont to do):
>
> Fatal error: Call to a member function on a non-object in /var/www/.../
> httpdocs/app/controllers/cities_controller.php on line 34
>
> Observations:
> 1) The action I'm invoking works fine when called from a browser
> 2) The 'member function' in question is none other than the standard
> built-in findAll(), which I would hope would be supported 'out of the
> box' when trying to invoke controller actions from the console.
>
> My Question:
> Am I approaching this the wrong way? Is there a shortcut to invoking
> controller actions from the console that I've overlooked?  App:import
> sure seems hacky.
>
> Reference:
>
> class ReportShell extends Shell
> {
> var $uses = array('City');
> var $tasks = array
> ('Project','DbConfig','Model','Controller','View','Plugin');
> var $CitiesController = null;
>
> function initialize()
> {
> $this->_loadModels();
>
> }
>
> function main()
> {
> App::import('Controller', 'Cities');
> $this->CitiesController = new CitiesController();
> $this->out($this->CitiesController->export_overall('Massachusetts'));
>
> }
> }
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to