“21 things I learned about CakePHP”

Published on and tagged with article  cakephp

This is the title of an article Matt Inman has written about his experiences with CakePHP. I think the article will help especially newbies to avoid some of the common problems.

6 comments baked

  • Jon Baer

    Can you explain the issue he points out with multiple inserts? (or @ least more specifically how/why it works) …

    $items = array(‘Item 1′,’Item 2′,’Item 3’);
    foreach ($items as $item) {
    $this->Post->id = false; // why?
    $this->Post->save(array(‘Post’ => array(‘title’ => $item)));

    I never knew about this + always ending up calling a new Model() when I needed to do a multiple insert (going back to refactor my stuff now), but knowing this part from the beginning would have saved me some time ..

  • nate

    It has to do with the fact that the id property of the model identifies it as being assigned to a particular record. Thus, if the id is null, false, or otherwise empty, it is treated as a new record when saved.

    Technically, the proper way to do this is to call $this->Post->create() to fully initialize the model for writing a new record.

  • Jon Baer

    Nate –

    Thank you for the clarification! Much appreciated ..

    – Jon

  • Daniel

    Yes, the article is very interesting. I´m baking cakes since three months and I am very surprised what´s possible with cakephp.
    Until reading this article I´ve never understood the define of CAKE_ADMIN! I spent many time implementing the admin section and design controller and friendly urls. The CAKE_ADMIN is great.
    But I don´t understand how protecting the admin folder. I test to make a admin/ folder in the app/ folder and protect it via htaccess. But when I call example.com/admin/controller/action I got a endless loop of the login message box… :(
    Any one can help me?

  • cakebaker

    @Daniel: There is an idea described in the manual: http://manual.cakephp.org/appendix/simple_user_auth

  • Daniel

    @cakebaker: Thank you! I´ve already found a solution. :o)
    It´s like the one in the manual.

© daniel hofstetter. Licensed under a Creative Commons License