Access functions or session data from a config file |
Hi all, I'd like to ask a question please.
I'm having the content (title, text etc) of my web pages stored in arrays like this: PHP Code: $this->data['homepage_content'] = array( So in my views I echo the array keys in order to display the content. In order to avoid to put too much content in my controllers, I though to store all this page content in a config file. My question is if its possible to do something like that in cases where I have some session data or some functions in my content too. Example: PHP Code: $this->data['another_page_content'] = array(
You probably could do that, as long as everything is in the correct state when you load the file.
Generally, I would lean towards putting the data into a model until I could work out a better way of storing it. Then, once the data is migrated to a storage medium (whether it's a database, a file, or whatever), the model could be updated to retrieve the data and return it to the controller without having to change the remaining code.
This seems to work in these cases:
PHP Code: // this is in my config file The problem comes when I try to mix some other config values, or some session data that I want to output with the rest content, for instance: PHP Code: // in config file
07-27-2015, 07:18 AM
(This post was last modified: 07-27-2015, 07:19 AM by ivantcholakov. Edit Reason: Typos )
Within the configuration file instead of
Code: 'title' => 'Hello ' . $this->session->userdata('username'), place Code: 'title' => 'Hello {{username}}', // Or some other preferred syntax. and then within the view replace the template "variable" with the actual username. (07-27-2015, 07:18 AM)ivantcholakov Wrote: Within the configuration file instead of Sorry, I 'm not sure if I had understand this correct, could you be more thorough a little bit, please???
Put a placeholder into the data ({{username}} in his example), retrieve the session data in your controller, then use str_replace() or some other method to replace your placeholder with the session data before sending it to the view.
|
Welcome Guest, Not a member yet? Register Sign In |