-1

I have the following code, which select product from table "products" based on the id.

public function p_details(){
$productIdNum = $this->params['detailID'];

        //$this->Product->read(null, $productIdNum);

        if(Validation::naturalNumber($productIdNum) == true){
            $itemById = $this->Product->find('all', array('conditions' =>
            array('Product.id' => $productIdNum)));

            if(count($itemById) > 0){
                $this->set('itemDetails', $itemById['Product']['id']);
            }
        }

    }

But when I try to print the variable "$itemDetails" in the view, like <?php echo $itemDetails['Product']['name']; ?> it's giving me this error: Undefined index: Product. If I change it to this like <?php echo $itemDetails['name']; ?> It's still give me the same error: Undefined index: name. I can't get to figure this out.

Michel
  • 1,065
  • 1
  • 10
  • 25
  • possible duplicate of [Reference - What does this error mean in PHP?](http://stackoverflow.com/questions/12769982/reference-what-does-this-error-mean-in-php) – Nunser Aug 27 '14 at 13:59
  • Next time you get index not found errors, you can do a `debug($array);` in your view to see what your array actually contains. – caitlin Aug 27 '14 at 21:47

1 Answers1

1

Well, the issue is that with $this->set('itemDetails', $itemById['Product']['id']); you assign an id, not an array, to the itemDetails variable. Change it to $this->set('itemDetails', $itemById);, and it should work.

dhofstet
  • 9,934
  • 1
  • 36
  • 37
  • Thanks for the response. I later noticed that as well, though it took me almost an hour to figure it out :) Thanks anyway for your reply – Michel Aug 28 '14 at 12:30