Reputation: 1
I get the following errors:
Notice (8): Undefined property: ProductsController::$Category
**
**
in \shop\app\controllers\products_controller.php on line 7
Model:
class Category extends AppModel {
var $name = 'Category';
var $hasMany = array('Product');
}
Controller:
class CategoriesController extends AppController{
var $name = 'Categories';}
class ProductsController extends AppController{
var $name ='Products';
function lists(){
$categories = $this->Category->find( 'all',array('order'=>'Category.id ASC'));
}
i have two controller class 1. CategoriesController 2. ProductsController. when i used lists method in categories controller, it's work, but in products controller it give error?
Upvotes: 0
Views: 7785
Reputation: 594
If you want to call methods from Category (or other associated) model you have to do it through the 'parent' (in this case Prodcut) model:
$categories = $this->Product->Category->find('all', array('order' => 'Category.id ASC'));
should work.
see http://book.cakephp.org/2.0/en/models/associations-linking-models-together.html#relationship-types
Upvotes: 3