[solved] where to store recurrent data ? - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: [solved] where to store recurrent data ? (/showthread.php?tid=21076) |
[solved] where to store recurrent data ? - El Forum - 07-30-2009 [eluser]mariek[/eluser] Hello, I'm coding an administration interface and some icons for modify, delete etc are on several pages. I use the html helper like this : Code: $image_add_props = array( My question is : where can I put the first part Code: $image_add_props = array( Thanks for your help [solved] where to store recurrent data ? - El Forum - 07-30-2009 [eluser]rogierb[/eluser] Add the image stuff in a helper, then load it once in the administration controller or in the autoload. <code> function _add_image_props() { return array( 'src' => base_url().'public/images/action_add.png', 'alt' => '+', 'class' => 'icon', 'title' => 'New' } </code> and in your view: <code> img(_image_add_props()) </code> [solved] where to store recurrent data ? - El Forum - 07-30-2009 [eluser]adamp1[/eluser] or going along the helper idea: Code: function icon($type) [solved] where to store recurrent data ? - El Forum - 07-30-2009 [eluser]mariek[/eluser] [quote author="rogierb" date="1248962621"]Add the image stuff in a helper, then load it once in the administration controller or in the autoload. [/quote] I like your solution, but wouldn't it be faster to store it as a constant somewhere ? (In fact, my question was more about where to store constants) [solved] where to store recurrent data ? - El Forum - 07-30-2009 [eluser]jedd[/eluser] adamp1's solution is pretty elegant - it means you can generate your properties for any given icon (assuming you have some nomenclature consistency). To store constants ... try config/config.php [solved] where to store recurrent data ? - El Forum - 07-30-2009 [eluser]adamp1[/eluser] or you could use the config/constants.php [solved] where to store recurrent data ? - El Forum - 07-30-2009 [eluser]mariek[/eluser] thanks everybody ! |