Log in


some more bugs in the developerWorks tutorial

« previous entry | next entry »
Dec. 20th, 2006 | 05:26 pm
posted by: bobalien in cakephp

I hit another little bug in the developerWorks tutorial; there's a problem in Part 2, Section 8: Putting your ACLs to work

Listing 17 reads:
function view($id) {
  $product = $this->Product->read(null, $id);
  if ($this->Acl->check($this->Session->read('user'), $id.'-'.$product['title'], 
    $this->set('product', $product);
  } else {
    $this->Session->setFlash('Only Registered Users may view this product.');

The problem is in the line:
$this->Acl->check($this->Session->read('user'), $id.'-'.$product['title'],

Specifically, $product['title']; In this tutorial, the Product model is associated to the Dealer model, so a ->read() on products returns both the Product and Dealer data:
    [Product] => Array
            [id] => 18
            [title] => Test Product
            [dealer_id] => 1
            [description] => Test Product Descript

    [Dealer] => Array
            [id] => 1
            [title] => Tor Johnson School Of Drama


As you can see, $product['title'] does not exist. There are 2 ways to fix this: the first is by placing $this->Product->recursive = 0 before the ->read(), which will only return the array of Product data, and no association data, but you probably want to display the association data, so I went with replacing $product['title'] with $product['Product']['title']. Hope this comes in handy for someone.

Link | Leave a comment | Share

Comments {0}