Welcome Guest, Not a member yet? Register   Sign In
Getting data from view file itself
#8

[eluser]xwero[/eluser]
It's been a look time rule of mine that libraries should not contain any framework code. Making a library with framework code makes them less reusable by default. This rules out a library.

A helper is framework bound because some use them and others don't. But i don't like helper functions to connect to a database because then the line between models and helpers fades. You could create a model that gets called in the helper but then you need to load two files instead of one.

So you end up creating a reusable model, because it's framework bound and connects to the data storage.

The dark side of a markup returning method/function is that the markup can change, which makes you add markup changing parameters to the method/function. This isn't good because then designers have no full control of all markup as some of it is hidden in php code. To give designers full control of the markup you should use a view file.

Now the practice, the model method would look like this
Code:
function overlay($table,$field,$where,$view)
{
    $this->db->select($field); // split up sql building methods for php4 compatibility
    $query = $this->db->get_where($table,$where);
    $row = $this->db->row();
    $data['overlay'] = $row->$field;
    return $this->load->view($view,$data,TRUE);
}
The helper code would look like this
Code:
function overlay($table,$field,$where,$view)
{
    $CI = & get_instance();
    $CI->load->model('overlaymodel','',TRUE);
    $data['overlay'] = $CI->overlaymodel->get_text($table,$field,$where);
    return $CI->load->view($view,$data,TRUE);
}
Lets say at some point the query needs to be changed but the original query still need to work too. In the model you can just add another method as for the helper function you have to create another model method and another helper function.

To summarize, if you create reusable methods/functions you should make the code as lean as possible. If it's a one time shot do what you find the easiest.


Messages In This Thread
Getting data from view file itself - by El Forum - 06-22-2008, 08:46 PM
Getting data from view file itself - by El Forum - 06-22-2008, 09:38 PM
Getting data from view file itself - by El Forum - 06-29-2008, 11:25 AM
Getting data from view file itself - by El Forum - 06-29-2008, 12:10 PM
Getting data from view file itself - by El Forum - 06-29-2008, 12:24 PM
Getting data from view file itself - by El Forum - 06-29-2008, 03:28 PM
Getting data from view file itself - by El Forum - 06-29-2008, 05:01 PM
Getting data from view file itself - by El Forum - 06-30-2008, 02:37 AM



Theme © iAndrew 2016 - Forum software by © MyBB