{"id":17,"date":"2009-05-18T13:20:00","date_gmt":"2009-05-18T13:20:00","guid":{"rendered":"http:\/\/www.codeboss.in\/web-funda\/?p=17"},"modified":"2009-05-18T13:20:00","modified_gmt":"2009-05-18T13:20:00","slug":"how-to-import-a-controller-in-cakephp","status":"publish","type":"post","link":"https:\/\/codeboss.in\/web-funda\/2009\/05\/18\/how-to-import-a-controller-in-cakephp\/","title":{"rendered":"How to import a controller in CakePHP"},"content":{"rendered":"<p>Suppose we have a controller named pages_controller.php, in which there is a function named index().<\/p>\n<p>Now we are working in an another controller named users_controller.php, and we want to use the index function defined in Pages Controller.<\/p>\n<pre class=\"brush: php;\">\nApp::import('Controller', 'Pages');\nclass UsersController extends AppController {\nvar $Pages;\nfunction beforeFilter() {\n$this->Pages =& new PagesController; \/*Loads the class*\/\n$this->Pages->constructClasses(); \/*Loads the model associations, components, etc. of the Pages controller*\/\n}\nfunction index() {\n$this->Pages->index();\n}\n}\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Suppose we have a controller named pages_controller.php, in which there is a function named index(). Now we are working in an another controller named users_controller.php, and we want to use the index function defined in Pages Controller. App::import(&#8216;Controller&#8217;, &#8216;Pages&#8217;); class UsersController extends AppController { var $Pages; function beforeFilter() { $this->Pages =&#038; new PagesController; \/*Loads the&hellip; <a class=\"more-link\" href=\"https:\/\/codeboss.in\/web-funda\/2009\/05\/18\/how-to-import-a-controller-in-cakephp\/\">Continue reading <span class=\"screen-reader-text\">How to import a controller in CakePHP<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[32,57],"class_list":["post-17","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-cakephp","tag-php","entry"],"_links":{"self":[{"href":"https:\/\/codeboss.in\/web-funda\/wp-json\/wp\/v2\/posts\/17","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/codeboss.in\/web-funda\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/codeboss.in\/web-funda\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/codeboss.in\/web-funda\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/codeboss.in\/web-funda\/wp-json\/wp\/v2\/comments?post=17"}],"version-history":[{"count":0,"href":"https:\/\/codeboss.in\/web-funda\/wp-json\/wp\/v2\/posts\/17\/revisions"}],"wp:attachment":[{"href":"https:\/\/codeboss.in\/web-funda\/wp-json\/wp\/v2\/media?parent=17"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/codeboss.in\/web-funda\/wp-json\/wp\/v2\/categories?post=17"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/codeboss.in\/web-funda\/wp-json\/wp\/v2\/tags?post=17"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}