简体   繁体   中英

Cakephp How to access AppController function in ctp file?

I am unable to access AppController.php function in my ctp file.

Please check my code:

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;
}

View/Messages/news_feed.ctp

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

When i running my code i am getting fllowing error

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]

Instead of

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

Do the request to any of your controllers instead of calling the app controller directly

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

As all your controllers inherit the method from the app controller

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM