Friday, November 21, 2008

Sementation fault with $uses variable in app_controller

Tonight, my Apache instance (OSX 10.5.5 Apache/2.2.9 (Unix) mod_ssl/2.2.9 OpenSSL/0.9.7l DAV/2 PHP/5.2.5 ) threw a segmentation fault when I tried to use one of my Models from the app_controller. In my code, this is how I had this setup:


class AppController extends Controller {
var $helpers = array('Html', 'Javascript', 'ForLayout', 'Tree');
var $components = array('Session', 'obAuth', 'Cookie');
var $uses = array('Contentpage'); /* THIS IS THE OFFENDING LINE */
...
}

I discovered this by systematically commenting out every piece of code that was implementing my Contentpage model. When I commented out the $uses variable, the segmentation fault went away.

So now my code reads like this to remind me.


class AppController extends Controller {
var $helpers = array('Html', 'Javascript', 'ForLayout', 'Tree');
var $components = array('Session', 'obAuth', 'Cookie');
/*
* WARNING!!! THIS CAUSES A SEGMENTATION FAULT!! DO NOT USE!!!
* var $uses = array('Contentpage');
*
*/
...
}


I've seen some issues in the CakePHP trac regarding segmentation faults, but nothing of this exact same nature.

As a side note, I thought I would try to use it from another controller. Initially this worked fine, but when it ran functions inside of obAuth, I got very unpredictable results. I'm still not really sure exactly what the nature of that error was. While I was debugging this, the segmentation fault started up again.

At any rate, I found a way to work around this so it doesn't hinder my work by putting a different layout on the controllers and actions that I originally wanted this functionality to execute on. However, I'm not sure what I'll do if I need a Model available to the app controller.

Has anyone else had this issue?

Wednesday, November 19, 2008

Define your own "for_layout" variables

Was looking for a way to add variables called $keywords_for_layout and $description_for_layout to provide meta data in my default layout page and I came across this from cakebaker. After I fought off the urge to set these fields in my controller all went well.

Define your own “for_layout” variables - cakebaker

Thursday, November 13, 2008

Acl/Auth vs. obAuth

Just spent the better part of a frustrating week dealing with the over-discussed and under documented Acl/Auth built into CakePHP 1.2. I finally threw up my hands in disgust even after I figured out how the whole system worked. I wanted to have granular control over my actions in my controllers and after I finally figured out that I had to have "all" my actions listed under my aco tree, I still got errors when I tried to log out of the application that my "logout" task was not properly mapped. All that time to figure out how to do this the out-of-the-box, Cake way only to hit yet another wall.

Finally, I passed the point in my project where I can no longer be held up with this and reverted to my old and dear friend obAuth. I had this configured in my 1.1 projects so I had all of this functionality outlined and in about 30 minutes, I had the authentication working with this simple batch of code in my app_controller.

	....<br />	var $components = array('obAuth');<br />	function beforeFilter() {<br />		$this->obAuth->startup($this);<br />		if(isset($this->params['admin'])){<br />			switch($this->params['controller']) {<br />				case 'groups':<br />				case 'pagetypes':<br />				case 'states':<br />				case 'countries':<br />				case 'types':<br />				case 'challenges':<br />					$this->obAuth->lock(array(ADMINISTRATOR)); // This is defined in core.php<br />					break;<br />				default:<br />					$this->obAuth->lock(array(ADMINISTRATOR, WEBMASTER)); // These are  defined in core.php<br />			}<br />			<br />		}<br />	}<br />...<br />


If I have this to do over again, I would probably look into setting the permissions on the controller level with ACL and then using the "controller" or "crud" as the action on $this->Auth->authorize. This is the way most people that have gotten it to work are successful with it. The most helpful site on this is Aran Johnson's site at Aran World. His sample kitchen web site gave me a lot of useful tips on how to work through the Auth part of this and as long as I stayed close to the demo code and didn't stray, I could make it work.

Sunday, November 9, 2008

CakePHP Useful links Catch-All from PseudoCoder.com

Just found this great list of links to all kinds of articles related to CakePHP. I have most of them already bookmarked, but I didn't want to lose this page.

CakePHP Tutorials :: PseudoCoder.com

Tuesday, November 4, 2008

Tree Drag and Drop with CakePHP

My goal is to use this along with the Tree behavior for what I'm building. Ideally, I'd like to find a similar JQuery solution for this as I'm trying to move all my code the the JQuery framework.

realm3: Drag and Drop Trees With CakePHP

Monday, November 3, 2008

CakePHP Model’s created / modified gotcha!

My created and modified fields were not updated in my database tables. I had painstakingly set them up with default values of '0000-00-00 00:00:00' and had them set (incorrectly, GRR!) to be not null. I thought that seemed strange as in my previous experience these fields always updated automagically. Then, I stumbled upon this little gem.

SANIsoft - PHP for E Biz» Blog Archive » CakePHP Model’s created / modified gotcha!

Now, I'm off to the work to change all these fields in all my tables. Ah, the joys of programming!

List displays with a blank option using FormHelper input

I just discovered a super easy way to generate a drop-down choice of related fields in CakePHP1.2.

This code in my controller:


$pagetypes = $this->Contentpage->Pagetype->find('list');
$this->set(compact('pagetypes'));


Coupled with this code in my view:


$form->input('pagetype_id');


Generates a select box with all my Pagetype options filled automagically. In addition, this remains stateful when I return to edit this.

This is such an improvement over older versions of CakePHP and what I've had to done in Ruby on Rails in the past.

One problem that this posed to me was getting a blank field or a field that prompted the user with a "Please select..." message. I knew there had to be a way to do this, so with a little fishing in Google's CakePHP Group, I came upon this answer:

To deliver a simple blank space in the drop-down:


$form->input('pagetype_id', array('empty' => true));

To deliver a "Please Select..." (or whatever you want) in the drop-down:


$form->input('pagetype_id', array('empty' => 'Please Select...'));


That's all there is to it! :)

Undefined variable: javascript (..default.ctp)

This error was causing me fits as it was not really throwing an error on the screen, only in my debug.log. What I found was that this was coming from not having my reference in the right controller. Each of my controllers had a similar reference:

class FaqsController extends AppController {
var $name = 'Faqs';
var $helpers = array('Html', 'Form', 'Javascript', 'Fck');
....
}

The error I was seeing was being generated by my default layout. All I had to do to fix this was put the following in my app_controller.php file.

class AppController extends Controller {
var $helpers = array('Html', 'Javascript');
}

Thanks to the V-TEK Channel blog and this link for pointing me in the right direction.

CakePHP Findings Blog

Hello all! I'm starting this blog to chronicle things I find related to development in CakePHP 1.2. I hope to collect my findings in this location through code snippets, URL references and framework pieces I find that work for me in my development of CMS-based applications for WonderGroup in Cincinnati, Ohio.