Question

I am using Cakephp 2.3 , i want to perform lots of common calculation in my several controllers. so i write those functions in my appcontroller and i cached some datas.. but what happens is my appController will become fatty.. so i create some component to perform these actions.. i dont know my approach is right or not..? please suggest..

  1. i want to use cache in my component, i tried this code. but nothing is cached..

        public $helpers =array('Cache');
    

and

     $result = Cache::read('fm_data', 'long');
       if (!$result) {
       $result =
 $this->TFmStation->find('all',array('contain'=>array('TLocation',
            'TLanguage','TMediaOrg','TContactPerson',
                    'TAddress','TFmProgram'=>array('TTargetGroup'))));
                       Cache::write('fm_data', $result, 'long');
                }
 return $result;
  1. please help me to how to use cache in component
  2. how to effectively use component class in cakephp in the case of more common functions in the application.. when i write these functions in appController it load all the functions so according to memory prespective, how to effectively use component
Was it helpful?

Solution

Model TFmStation is best place to have the above logic. Components are there for generic functionality like UploadComponent, EmailComponent, RecaptchaComponent etc. If your logic part have something to do with model, then it should go into that model.

A Model can be called from AppController.php in a similar fashion as you calling your Component.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top