Welcome Guest, Not a member yet? Register   Sign In
[solved] where to store recurrent data ?
#1

[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(
    'src' => 'public/images/action_add.png',
    'alt' => '+',
    'class' => 'icon',
    'title' => 'New'
);

img($image_add_props)

My question is : where can I put the first part
Code:
$image_add_props = array(
    'src' => 'public/images/action_add.png',
    'alt' => '+',
    'class' => 'icon',
    'title' => 'New'
);
so I don't have to redeclare it on each view ?

Thanks for your help
#2

[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>
#3

[eluser]adamp1[/eluser]
or going along the helper idea:
Code:
function icon($type)
{
$image_props = array(
    'src' => 'public/images/action_' . $type . '.png',
    'alt' => $type,
    'class' => 'icon',
    'title' => $type
);

return img($image_props)
}
#4

[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)
#5

[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
#6

[eluser]adamp1[/eluser]
or you could use the config/constants.php
#7

[eluser]mariek[/eluser]
thanks everybody !




Theme © iAndrew 2016 - Forum software by © MyBB