I'm new to cakephp. I have a class called Rest that is shared by two controllers: Pages and Categories.
I therefore thought of making the instance of the class in the AppController:
class AppController extends Controller {
public $rest;
public function DoRest() {
require 'Component/Rest.php';
if(!isset($this->rest))
$this -> rest = new Rest();
return $this -> rest;
}
}
then i can access it at the categoriesController:
public function index()
{
if ($this->request->is('requested')) {
return $this -> DoRest() -> getCategories();
} else {
$this -> set('categories', $this -> DoRest() -> getCategories());
}
}
and in the pages controller:
public function category() {
$this -> set('items',$this -> DoRest() -> getCategoryById($this->request->query['id']));
}
within category.ctp i can access the categories through:
$categories = $this->requestAction('categories/index');
however now im getting this error:
Error: Cannot redeclare class Rest
What have i done wrong?