How can i access data from another controller?

My problem is this. I have a controller “FacsController”, and a method.

public function access()
{
$facs = $this->Facs->find()->all();
return $facs;
}

This method works perfectly, data is returned properly. But what I need is to call this method within another controller, “PagesController”.

public function display()
{
$var = new FacsController();
$var->access();
$this->set(‘vars’, $var);
$this->set(’_serialize’, [‘vars’]);
}

Unfortunately here I do not get the data returned from the FacsController. Can someone help me? What am I doing wrong.

Do not call controller methods from another controller. Are you speaking about Cake’s pages controller? If so it should not call anything like this, as it main purpose is to serve static content - a page.

If your pages controller is your own than there is a good chance that your facs and pages are associated, so you can acess facs model methods from pages controller.

To access the Facs model from your PagesController you have to load the model explicitly:

public function display()
{
$this->loadModel(“Facs”);
$facs = $this->Facs->find()->all();

$this->set(‘facs ‘, $facs );
$this->set(’_serialize’, ['facs ']);
}