Latest blog entry: cakePHP

Here are some tips from newbie to newbie, with problems and their solutions as I came across them whilst testing the cakePHP framework. Read more... (1 Comments)

Things that took me longer than necessary to find

Here are some tips from newbie to newbie, with problems and their solutions as I came across them whilst testing the cakePHP framework. Let me know if they help you...or if there is a problem.

  1. Adding a title attribute to $html->link

I have no idea why this isn't found here but to add attributes such as title, class or ids to a link, you need to add a third parameter as an array:
echo $html->link($dolist['Dolist']['name']), array('controller'=>'Dolist','action'=>'view', $dolist['Dolist']['id']),array('title'=>$dolist['Dolist']['description']));
where the first is the text displayed the second array is the actual link, divided into controller (optional), action and parameters, and the third takes all yout html attributes like title.

  1. Deleting related items

Deleting related items(i.e. all posts when a thread is deleted) is a breeze with cakePHP. All you need to do is make that model dependent (not dependant, a typo that cost me 20 minutes). So in my posts model I would have

  1. var $belongsTo = array(
  2. 'Thread' => array(
  3. 'className' => 'Thread',
  4. 'foreignKey' => 'thread_id',
  5. 'dependent'=> true
  6. )
  7. );
Calling $this->Thread->del($id) will now not only delete all Threads, but also any related posts which have a corresponding thread_id. Great!

Write a comment

  • Required fields are marked with *.

If you have trouble reading the code, click on the code itself to generate a new random code.
Security Code:  
Anonymous
Posts: 1
Comment
Re: Things that took me longer than necessary to find
Reply #1 on : Wed July 14, 2010, 21:58:29
to find your tip cost me 10 minutes ...
so i earned 10

thanks