Reputation: 6241
I am using a layout which has three lists which are created from a database query. I would propose to put this data in the session so the app doesn't have to query the database on every page load.
The admin section of the app will not need this data as it uses a different layout. In cakePHP where is the best place to put the logic that sets this session data?
Is the best approach to create another controller that extends the AppController and looks after setting this session data?
Upvotes: 2
Views: 230
Reputation: 4399
You can create elements for these 3 lists. The best way to do this is using requestAction and elements. Using elements also allows you to cache the output, which is always a good idea.
Upvotes: 1
Reputation: 5481
specify it in beforeRender() in AppController. If you have beforeRender() in any controller, remember to call parent::beforeRender()
Upvotes: 1
Reputation: 1879
I'm still fairly new to CakePHP, so this may not be the best way to do this, but I would have a model using a custom behaviour to checks if session data has been loaded and load the data from the session or database dependant on whether its been loaded already. So I think the code could be written as a behaviour and the model would then be used wherever necessary. Someone correct me if I'm wrong here.
Upvotes: -1