Welcome Guest, Not a member yet? Register   Sign In
Passing a function
#1

[eluser]Kola[/eluser]
Hello,

I'm thinking a bit over this one. Is it possible to pass a function to the view document? Basicly I have this administration page for some images where I'd like to print out all my images in the database.

Do I have to get all the data from the controller and store it in some massive array. Or can I somehow make the function callable from the viewpage. My initial idea was to do something like:

Code:
<div id='box_holding_images'>
&lt;?php

  $this->Controller->GetImages();

?&gt;
</div>
#2

[eluser]bretticus[/eluser]
YES! This is what helpers are for. Strictly speaking, GetImages should not be a controller method anyways. Some people would even discourage you from storing images in your database.
#3

[eluser]Kola[/eluser]
Yeah what I'm storing is merely the product nr. and a small text like 'Wierd fancy ear ring!' for small captions.
#4

[eluser]bretticus[/eluser]
[quote author="Kola" date="1287093525"]Yeah what I'm storing is merely the product nr. and a small text like 'Wierd fancy ear ring!' for small captions.[/quote]

This is how I do it also.

So yes, create a helper that can access your database.

Code:
//for example.
function get_images($id) {
$CI =& get_instance();
return $CI->db->where('image_id', $id)->get('images')->row();
}

Or better yet, grab the information from a Model and just pass it in the second param of your load view call.




Theme © iAndrew 2016 - Forum software by © MyBB