In CakePhp 1.3:
orry if this question is stupid, but I really don’t know why my code is not working, maybe someone can point me in the right direction. My problem/question is: how can I access a function in a controller from the app_controller?
I have an app/controllers/items_controller.php:
class ItemsController extends AppController {
...
function holaItem(){
$i = 1;
return $j = 2;
}
...
}
app_controller.php
class AppController extends Controller {
var $uses = array('Item');
function beforeFilter() {
parent::beforeFilter();
$result2 = $this->Item->holaItem();
}
}
Why “$this->Item->holaItem()” is not working?
Thanks!
$this->Itemreference theItemmodel. However, theholaItem()method exists in theItemcontroller.Either move it to your
Itemmodel or move thebeforeFilter()to yourItemcontroller.I’d encourage you to read and understand how CakePHP does MVC.