<?xml version="1.0" encoding="UTF-8"?><!-- generator="wordpress/2.3.3" -->
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	>
<channel>
	<title>Comments on: PHP: Writing a Console Program in CakePHP</title>
	<link>http://twit88.com/blog/2008/02/14/php-writing-a-console-program-in-cakephp/</link>
	<description>Good judgement comes from experience, and experience comes from bad judgement.</description>
	<pubDate>Wed, 07 Jan 2009 22:45:49 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.3.3</generator>
		<item>
		<title>By: oh4real</title>
		<link>http://twit88.com/blog/2008/02/14/php-writing-a-console-program-in-cakephp/#comment-31473</link>
		<dc:creator>oh4real</dc:creator>
		<pubDate>Fri, 05 Dec 2008 18:50:55 +0000</pubDate>
		<guid>http://twit88.com/blog/2008/02/14/php-writing-a-console-program-in-cakephp/#comment-31473</guid>
		<description>I've set up triggers in Models based on what is being saved or updated. For controller-based access, I used inside the Models:

	$this-&#62;requestAction('/mails/method/param1/param2');

And it worked fine. 

BUT, a Shell using the model and making the same save/update got no love as requestAction is banned in ShellDispatcher.

So, I did this and now use it in the Models, whether called by a controller via web interaction or shell called from crontab.

     function beforeSave () {
	App::import('Controller','Mails');
	$this-&#62;MailsController = new MailsController();
	$this-&#62;MailsController-&#62;constructClasses();
	$this-&#62;MailsController-&#62;Email-&#62;startup($this-&#62;MailsController);
	if(save some triggering value) {
	     $this-&#62;MailsController-&#62;method1(param1,param2);
	} elseif(updating some triggering value) {
	     $this-&#62;MailsController-&#62;method2(param1,param2);
	}

I am sure there is something horribly wrong with this, but it works and until I learn otherwise...

I also created the EmailTask for Shell specific emails, but might be able to use the code above as well to keep all emails in one location, ie /app/views/elements/emails

regards,
oh4real</description>
		<content:encoded><![CDATA[<p>I&#8217;ve set up triggers in Models based on what is being saved or updated. For controller-based access, I used inside the Models:</p>
<p>	$this-&gt;requestAction(&#8217;/mails/method/param1/param2&#8242;);</p>
<p>And it worked fine. </p>
<p>BUT, a Shell using the model and making the same save/update got no love as requestAction is banned in ShellDispatcher.</p>
<p>So, I did this and now use it in the Models, whether called by a controller via web interaction or shell called from crontab.</p>
<p>     function beforeSave () {<br />
	App::import(&#8217;Controller&#8217;,'Mails&#8217;);<br />
	$this-&gt;MailsController = new MailsController();<br />
	$this-&gt;MailsController-&gt;constructClasses();<br />
	$this-&gt;MailsController-&gt;Email-&gt;startup($this-&gt;MailsController);<br />
	if(save some triggering value) {<br />
	     $this-&gt;MailsController-&gt;method1(param1,param2);<br />
	} elseif(updating some triggering value) {<br />
	     $this-&gt;MailsController-&gt;method2(param1,param2);<br />
	}</p>
<p>I am sure there is something horribly wrong with this, but it works and until I learn otherwise&#8230;</p>
<p>I also created the EmailTask for Shell specific emails, but might be able to use the code above as well to keep all emails in one location, ie /app/views/elements/emails</p>
<p>regards,<br />
oh4real</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: calzone</title>
		<link>http://twit88.com/blog/2008/02/14/php-writing-a-console-program-in-cakephp/#comment-29528</link>
		<dc:creator>calzone</dc:creator>
		<pubDate>Fri, 21 Nov 2008 18:05:57 +0000</pubDate>
		<guid>http://twit88.com/blog/2008/02/14/php-writing-a-console-program-in-cakephp/#comment-29528</guid>
		<description>Cakebaker (http://cakebaker.42dh.com/2007/05/07/writing-a-custom-cakephp-console-script/) resolved my issue.

The answer is that  after the instantiation, the controller needs to be initialized:

$this-&#62;CitiesController = new CitiesController();
$this-&#62;CitiesController-&#62;constructClasses();

The cake manual mentions this method at http://book.cakephp.org/view/429/constructClasses</description>
		<content:encoded><![CDATA[<p>Cakebaker (http://cakebaker.42dh.com/2007/05/07/writing-a-custom-cakephp-console-script/) resolved my issue.</p>
<p>The answer is that  after the instantiation, the controller needs to be initialized:</p>
<p>$this-&gt;CitiesController = new CitiesController();<br />
$this-&gt;CitiesController-&gt;constructClasses();</p>
<p>The cake manual mentions this method at <a href="http://book.cakephp.org/view/429/constructClasses" rel="nofollow">http://book.cakephp.org/view/429/constructClasses</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: calzone</title>
		<link>http://twit88.com/blog/2008/02/14/php-writing-a-console-program-in-cakephp/#comment-29093</link>
		<dc:creator>calzone</dc:creator>
		<pubDate>Fri, 21 Nov 2008 06:44:07 +0000</pubDate>
		<guid>http://twit88.com/blog/2008/02/14/php-writing-a-console-program-in-cakephp/#comment-29093</guid>
		<description>I tried setting up a console program following your example here but was stymied by the fact that even though a controller action can be invoked from the console, any model method calls that action contains will fail with "Fatal error: Call to a member function on a non-object."

Am I doing something wrong or is there some additional scoping workaround I need to add to the code somehow somewhere?</description>
		<content:encoded><![CDATA[<p>I tried setting up a console program following your example here but was stymied by the fact that even though a controller action can be invoked from the console, any model method calls that action contains will fail with &#8220;Fatal error: Call to a member function on a non-object.&#8221;</p>
<p>Am I doing something wrong or is there some additional scoping workaround I need to add to the code somehow somewhere?</p>
]]></content:encoded>
	</item>
</channel>
</rss>
