Quantcast

use different model in different controller.

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

use different model in different controller.

Rgarg

Hi!!!!

i am using two controller
    Products
    categories

in index page i want to display all information about products as well
as 'category name'.category name comes from Categories table.

Model of Products is:

<?php
  class Product extends AppModel
  {
    var $name = 'Product';
    var $belongsTo = array ('Category' => array('className' =>
'Category','conditions'=>'','order'=>'',
'foreignKey'=>'category_id'));
  }
?>


controller is:

class ProductsController extends AppController
{
  //var $scaffold;
  var $name = 'Products';
var $helpers = array('Html', 'Form', 'Tree' );
var $components = array('Upload');

function index() {
        $this->Product->recursive = 0;
        $this->set('products', $this->Product->findAll());
}



in index() i want to use

$this->set('data', $this->Category->findAllThreaded(null, null,
'parent_id'));
                $CategoryArray = $this->Category->generateList(null, 'parent_id');
        $this->set('CategoryArray', $CategoryArray);

Please help me............
What to do for this.

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

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: use different model in different controller.

Anupom

Try this

$this->set('data', $this->Product->Category->findAllThreaded(null, null,
'parent_id'));
               $CategoryArray =
$this->Product->Category->generateList(null, 'parent_id');
       $this->set('CategoryArray', $CategoryArray);

On Feb 2, 2008 1:47 PM, Rgarg <[hidden email]> wrote:

>
> Hi!!!!
>
> i am using two controller
>     Products
>     categories
>
> in index page i want to display all information about products as well
> as 'category name'.category name comes from Categories table.
>
> Model of Products is:
>
> <?php
>   class Product extends AppModel
>   {
>     var $name = 'Product';
>     var $belongsTo = array ('Category' => array('className' =>
> 'Category','conditions'=>'','order'=>'',
> 'foreignKey'=>'category_id'));
>   }
> ?>
>
>
> controller is:
>
> class ProductsController extends AppController
> {
>   //var $scaffold;
>   var $name = 'Products';
> var $helpers = array('Html', 'Form', 'Tree' );
> var $components = array('Upload');
>
> function index() {
>         $this->Product->recursive = 0;
>         $this->set('products', $this->Product->findAll());
> }
>
>
>
> in index() i want to use
>
> $this->set('data', $this->Category->findAllThreaded(null, null,
> 'parent_id'));
>                 $CategoryArray = $this->Category->generateList(null, 'parent_id');
>         $this->set('CategoryArray', $CategoryArray);
>
> Please help me............
> What to do for this.
>
> >
>



--
Thanks
Anupom
Trippert Inc. [http://www.trippert.com]
GopherNow. [http://www.gophernow.com/]
Homepage. [http://www.anupom.wordpress.com/]

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

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: use different model in different controller.

brian_gaff
In reply to this post by Rgarg

Anupom has already told you the correct way to do it; however, if you
really really want to do it like:

 $this->Category->find();

Then you need to add this line to the top of your Products controller:

 var $uses = array('Product', 'Category');


BRIAN

On Feb 1, 11:47 pm, Rgarg <[hidden email]> wrote:

> Hi!!!!
>
> i am using two controller
>     Products
>     categories
>
> in index page i want to display all information about products as well
> as 'category name'.category name comes from Categories table.
>
> Model of Products is:
>
> <?php
>   class Product extends AppModel
>   {
>     var $name = 'Product';
>     var $belongsTo = array ('Category' => array('className' =>
> 'Category','conditions'=>'','order'=>'',
> 'foreignKey'=>'category_id'));
>   }
> ?>
>
> controller is:
>
> class ProductsController extends AppController
> {
>   //var $scaffold;
>   var $name = 'Products';
> var $helpers = array('Html', 'Form', 'Tree' );
> var $components = array('Upload');
>
> function index() {
>         $this->Product->recursive = 0;
>         $this->set('products', $this->Product->findAll());
>
> }
>
> in index() i want to use
>
> $this->set('data', $this->Category->findAllThreaded(null, null,
> 'parent_id'));
>                 $CategoryArray = $this->Category->generateList(null, 'parent_id');
>         $this->set('CategoryArray', $CategoryArray);
>
> Please help me............
> What to do for this.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake PHP" group.
To post to this group, send email to [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: use different model in different controller.

Keymaster-2

Don't use $uses, ever. It is terrible for performance.

Always access models through their associations, ie. $this->model1-
>model2->find();

If you don't have any associations to the model you want, use the
following before accessing your model:

App::import('Model', 'Product');
$tmpProduct = new Product();
$tmpProduct->find();
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake PHP" group.
To post to this group, send email to [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: use different model in different controller.

Rgarg
In reply to this post by Anupom

Thats is working now.

thank you so much Anupom.
:-)

On Feb 3, 9:08 am, Anupom <[hidden email]> wrote:

> Try this
>
> $this->set('data', $this->Product->Category->findAllThreaded(null, null,
> 'parent_id'));
>                $CategoryArray =
> $this->Product->Category->generateList(null, 'parent_id');
>        $this->set('CategoryArray', $CategoryArray);
>
> On Feb 2, 2008 1:47 PM, Rgarg <[hidden email]> wrote:
>
>
>
>
>
> > Hi!!!!
>
> > i am using two controller
> >     Products
> >     categories
>
> > in index page i want to display all information about products as well
> > as 'category name'.category name comes from Categories table.
>
> > Model of Products is:
>
> > <?php
> >   class Product extends AppModel
> >   {
> >     var $name = 'Product';
> >     var $belongsTo = array ('Category' => array('className' =>
> > 'Category','conditions'=>'','order'=>'',
> > 'foreignKey'=>'category_id'));
> >   }
> > ?>
>
> > controller is:
>
> > class ProductsController extends AppController
> > {
> >   //var $scaffold;
> >   var $name = 'Products';
> > var $helpers = array('Html', 'Form', 'Tree' );
> > var $components = array('Upload');
>
> > function index() {
> >         $this->Product->recursive = 0;
> >         $this->set('products', $this->Product->findAll());
> > }
>
> > in index() i want to use
>
> > $this->set('data', $this->Category->findAllThreaded(null, null,
> > 'parent_id'));
> >                 $CategoryArray = $this->Category->generateList(null, 'parent_id');
> >         $this->set('CategoryArray', $CategoryArray);
>
> > Please help me............
> > What to do for this.
>
> --
> Thanks
> Anupom
> Trippert Inc. [http://www.trippert.com]
> GopherNow. [http://www.gophernow.com/]
> Homepage. [http://www.anupom.wordpress.com/]
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake PHP" group.
To post to this group, send email to [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: use different model in different controller.

Rgarg
In reply to this post by brian_gaff

thats working now..

Thank you so much

:-)


On Feb 3, 9:16 am, brian_gaff <[hidden email]> wrote:

> Anupom has already told you the correct way to do it; however, if you
> really really want to do it like:
>
>  $this->Category->find();
>
> Then you need to add this line to the top of your Products controller:
>
>  var $uses = array('Product', 'Category');
>
> BRIAN
>
> On Feb 1, 11:47 pm, Rgarg <[hidden email]> wrote:
>
> > Hi!!!!
>
> > i am using two controller
> >     Products
> >     categories
>
> > in index page i want to display all information about products as well
> > as 'category name'.category name comes from Categories table.
>
> > Model of Products is:
>
> > <?php
> >   class Product extends AppModel
> >   {
> >     var $name = 'Product';
> >     var $belongsTo = array ('Category' => array('className' =>
> > 'Category','conditions'=>'','order'=>'',
> > 'foreignKey'=>'category_id'));
> >   }
> > ?>
>
> > controller is:
>
> > class ProductsController extends AppController
> > {
> >   //var $scaffold;
> >   var $name = 'Products';
> > var $helpers = array('Html', 'Form', 'Tree' );
> > var $components = array('Upload');
>
> > function index() {
> >         $this->Product->recursive = 0;
> >         $this->set('products', $this->Product->findAll());
>
> > }
>
> > in index() i want to use
>
> > $this->set('data', $this->Category->findAllThreaded(null, null,
> > 'parent_id'));
> >                 $CategoryArray = $this->Category->generateList(null, 'parent_id');
> >         $this->set('CategoryArray', $CategoryArray);
>
> > Please help me............
> > What to do for this.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake PHP" group.
To post to this group, send email to [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: use different model in different controller.

Rgarg
In reply to this post by Keymaster-2

thanks

its working now.

:-)

On Feb 3, 11:31 am, keymaster <[hidden email]> wrote:

> Don't use $uses, ever. It is terrible for performance.
>
> Always access models through their associations, ie. $this->model1-
>
> >model2->find();
>
> If you don't have any associations to the model you want, use the
> following before accessing your model:
>
> App::import('Model', 'Product');
> $tmpProduct = new Product();
> $tmpProduct->find();
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake PHP" group.
To post to this group, send email to [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: use different model in different controller.

Rgarg
In reply to this post by Keymaster-2

if i use  App::import('Model', 'Product');

it gives

Fatal error: Class 'App' not found in /opt/lampp/htdocs/
cake_1.1.19.6305/app/controllers/products_controller.php on line 16



On Feb 3, 11:31 am, keymaster <[hidden email]> wrote:

> Don't use $uses, ever. It is terrible for performance.
>
> Always access models through their associations, ie. $this->model1-
>
> >model2->find();
>
> If you don't have any associations to the model you want, use the
> following before accessing your model:
>
> App::import('Model', 'Product');
> $tmpProduct = new Product();
> $tmpProduct->find();
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake PHP" group.
To post to this group, send email to [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Loading...