# How can i access data from another controller?

**URL:** <https://discourse.cakephp.org/t/how-can-i-access-data-from-another-controller/1441>\
**Category:** Need Help\
**Created:** [November 3, 2016, 1:13pm UTC](https://discourse.cakephp.org/t/how-can-i-access-data-from-another-controller/1441 "2016-11-03T13:13:43Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![rodolfologan](https://avatars.discourse-cdn.com/v4/letter/r/b5ac83/32.png) [@rodolfologan](https://discourse.cakephp.org/u/rodolfologan)\
**Post date:** [November 3, 2016, 1:13pm UTC](https://discourse.cakephp.org/t/how-can-i-access-data-from-another-controller/1441/1 "2016-11-03T13:13:43Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![rrd](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/rrd/32/113_2.png) [@rrd](https://discourse.cakephp.org/u/rrd)\
**Post date:** [November 4, 2016, 1:56pm UTC](https://discourse.cakephp.org/t/how-can-i-access-data-from-another-controller/1441/2 "2016-11-04T13:56:53Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![benzo](https://avatars.discourse-cdn.com/v4/letter/b/4491bb/32.png) [@benzo](https://discourse.cakephp.org/u/benzo)\
**Post date:** [November 4, 2016, 8:05pm UTC](https://discourse.cakephp.org/t/how-can-i-access-data-from-another-controller/1441/3 "2016-11-04T20:05:45Z")

</div>

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 ']);  
> }
