1. Don't store your results in $this->Product.  That is confusing.

2. To expose data to the view use $this->set('variable_name',
$data_for_variable);

3. I have never used loadModel.  Instead, at the top of the controller
I would add the unassociated model to the $uses  array.

For example in CategoriesController:

var $uses = array('Category', 'Product');  /* Product is a
unassociated model that we want to access */

4. Then your code would like like

$this->set('catProds', $this->Product->getProductsByCategory($id,
$start, $limit, $sort));
$this->set('category', $this->Category->read());

5. To organize the results of the getProductsByCategory function, loop
through and organize the data inside the getProductByCategory before
you return.

6. I think you are slightly misunderstanding the concept of a Model.
You might read over the manual section again.



On May 9, 5:44 am, johnvv <[EMAIL PROTECTED]> wrote:
> Ok, I was able to get around the error messages with this:
>
> // CategoryController
> ..
> function view($id){
> ..
>    loadModel('Product');
>    $p = new Product();
>    $this->Product = $p->getProductsByCategory($id, $start, $limit,
> $sort);
>    pr($this);
>    $this->set('category', $this->Category->read());
>
> }
>
> Would show that the Category['Product'] object was populated with an
> array of products.  For example
> ['Category']['Product'][0]['Product'][0]['product_name'] = 'Acme
> XYZ123'
> ['Category']['Product'][1]['Product'][0]['product_name'] = 'Acme
> MZ456'
> However the view.thtml output did not show any recognition of a
> Product object and I could not find a way to access it.  Do I need to
> do a Save() call or something?
> I didn't even get into trying to build the ProductImage model which
> brings up an important question...
>
> With 1 query, can I build 2 or more Models??
>
> For instance, if I call a function in the Product model that joins the
> product_image table, can I use the output to build both the Product
> and ProductImage models?
>
> On May 9, 12:19 pm, "Jon Bennett" <[EMAIL PROTECTED]> wrote:
>
> > > Hmm... ok, I understand setting up the function in the Product model
> > > to run the query but I'm confused about the CategoryController.
> > > If I try to run:
>
> > $catProds = $this->Category->Product->getCategoryProducts($categoryId);
>
> > you have to traverse the associations tree back. If you're working
> > within CategoriesController, then Product is an associated table to
> > Category.
>
> > try pr($this->Category); // pr is cake shorthand for print_r
>
> > hth
>
> > jon


--~--~---------~--~----~------------~-------~--~----~
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