Ok,

You might be able to do this:


Add a relationship in your user model; example: User hasMany Product
etc...

Then in you controller you can do the following:


$this->User->id = $id; //Passed in the function

$userProducts = $this->User->Product->find('all',$params =
array(   'conditions' => add any extra condition in here , it can be
an array as well.       ));


//then set the data to be available int he view.

Better yet, you could write a custom function in the User model to get
products for the user, that would save typying etc..

in user.php //model

function getProduct(){
//The model must be associated before trying to do this.

return $this->Product->find();

}

in the controller you do:

$userProducts = $this->User->getProduct();  //SImple

Hope it helps...

Cheers



gabriel wrote:
> Hi, i hope someone can help me here please, I need help with my
> controller function, I want to get products by user_id, unfortunately
> I have no idea where to start, help will be greatfully received.
>
> Here is my code so far...
>
>
> class ProductsController extends AppController {
>     var $name = 'Products';
>     var $uses = array('Product', 'Category', 'User');
>     var $components = array('Search','Files');
>
>           function view() {
>               $this->Product->recursive = 0;
>               $this->set('products', $this->paginate());
>               $this->set('users', $this->User->read(null, $id));
>
>       }
>
> Thanks
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"CakePHP" 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