some more bugs in the developerWorks tutorial
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:
The problem is in the line:
$this->Acl->check($this->Session->read('u ser'), $id.'-'.$product['title'],
'read')
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:
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.
Listing 17 reads:
function view($id) {
$product = $this->Product->read(null, $id);
if ($this->Acl->check($this->Session->read('user'), $id.'-'.$product['title'],
'read'))
{
$this->set('product', $product);
} else {
$this->Session->setFlash('Only Registered Users may view this product.');
$this->redirect('/users/register');
}
}
The problem is in the line:
$this->Acl->check($this->Session->read('u
'read')
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:
Array
(
[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.
