Hi,

I'm the beginner in Cake but can you try this code:

         function admin_index($id) {
                 $this->Product->recursive = 0;
                 $products1 = $this->Product-
>findAllByCategory_id($id);
                 $this->set('products', $products1);

                 if(array_key_exists('category_id',$products1)) {
                         $this->data['Category']['id'] = $products1[0]
['Product']['category_id'];
                 } else {
                         $this->data['Category']['id'] = $id;
                 }

         }

I think that $this->set function create a variable in the view and you
can't use it in the controller.

On 24 Cze, 20:02, r557 <[EMAIL PROTECTED]> wrote:
> In my function i would like to define a variable $data['Category']
> ['id'].  If the findAllByCategory_id($id) returns no records, i would
> like $this->data['Category']['id'] to be the value of the $id passed
> into the function.
>
>         function admin_index($id) {
>                 $this->Product->recursive = 0;
>                 $this->set('products', 
> $this->Product->findAllByCategory_id($id));
>
>                 if(array_key_exists('category_id',$products)) {
>                         $this->data['Category']['id'] = 
> $products[0]['Product']
> ['category_id'];
>                 } else {
>                         $this->data['Category']['id'] = $id;
>                 }
>
>         }
>
> I am getting the error: Notice: Undefined variable: products in C:
> \apache2triad\htdocs\sonsofmaxwell\new\app\controllers
> \products_controller.php on line 24 Warning: array_key_exists(): The
> second argument should be either an array or an object in C:
> \apache2triad\htdocs\sonsofmaxwell\new\app\controllers
> \products_controller.php on line 24 and line 24 would be the
> if(array_key...) line.
>
> I am wondering if i should be using afterfind in this case??  but
> never used it before, i only need this used within one function in my
> Controller.


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to