我无法在我的ctp文件中访问AppController.php函数。
请检查我的代码:
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']);
当我运行我的代码时,我得到了错误
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]
答案 0 :(得分:0)
而不是
echo $this->requestAction('/app/commonEmotions/'.$getNewsFeed['News_feed']['news']);
向任何控制器发出请求,而不是直接调用app控制器
echo $this->requestAction('/Smiley/commonEmotions/'.$getNewsFeed['News_feed']['news']);
因为所有控制器都从app控制器继承该方法