2014-09-26 65 views
0

我无法访问我的ctp文件中的AppController.php函数。Cakephp如何访问ctp文件中的AppController函数?

请检查我的代码:

AppController的

public function commonEmotions($text=null){ 
     $this->loadModel("Sticker"); 
     $this->loadModel("Smiley"); 
     //Smiley 
     $getSmiley=$this->Smiley->find('all',array('fields'=>array('Smiley.image','Smiley.symbol'))); 
     $emotions=$this->Custom->parseEmotions($text,$getSmiley); 
     //Sticker 
     $getSticker = $this->Sticker->find('all',array('fields'=>array('Sticker.uniq_id','Sticker.image'))); 
     $message=$this->Custom->parseStickers($emotions,$getSticker); 
     return $message; 
} 

查看/信息/ news_feed.ctp

echo $this->requestAction('/app/commonEmotions/'.$getNewsFeed['News_feed']['news']); 

当我运行我的代码我得到fllowing错误

Notice (8): Undefined index: News_feed [APP\View\Messages\news_feed.ctp, line 188] 

Warning (2): Missing argument 1 for AppController::commonEmotions() [APP\Controller\AppController.php, line 51] 
+5

不要把它放在AppController中。将其放入扩展AppController的特定控制器中。另外:你应该总是提到你正在使用的确切cakephp版本。 – mark 2014-09-26 08:03:58

+2

我觉得'$ getNewsFeed ['News_feed'] ['news']'为空 – 2014-09-26 08:04:34

回答

0

代替

echo $this->requestAction('/app/commonEmotions/'.$getNewsFeed['News_feed']['news']); 

的要求去做任何你的控制器,而不是调用应用程序控制器直接

echo $this->requestAction('/Smiley/commonEmotions/'.$getNewsFeed['News_feed']['news']); 

由于所有的控制器从应用程序控制器继承方法

相关问题