Welcome Guest, Not a member yet? Register   Sign In
Acces controller function from library / alternative work around?
#1

[eluser]Bramme[/eluser]
Hey everybody

Here's my issue: I'm developping a CRUD application that generates standard HTML tables and forms for my database tables. I've extended the CI_Controller with MY_Controller and have written a few basic methods (index(), edit()...) that generate default html. For every table in my database, I then create a controller that extends from MY_Controller. This ensures every controller, extended from MY_Controller has the same pages (index, edit).

If I need to display something other than the default HTML, I just overwrite the index/edit function in my table controller.

The index page of MY_Controller produces an HTML table with all the fields in the database and displays those fields as flat text. The function that generates the html table, is in a library called Crud. So in crud.php I do this at a certain point:
Code:
foreach ($query->result() as $temp_row)
{
    foreach ($fields as $field => $field_options)
    {            
        $row[] = $temp_row->$field;
    }
    $this->CI->table->add_row($row);
}
Now, sometimes, I want something more than flat text. So I though I would try something as
Code:
foreach ($query->result() as $temp_row)
{
    foreach ($fields as $field => $field_options)
    {            
        $row[] = $this->CI->MY_Controller->_format_table_field($field, $temp_row);
    }
    $this->CI->table->add_row($row);
}
And put the following in MY_Controller.php
Code:
function _format_table_field($field, $datarow)
{
    return $datarow->$field;
}
Do I need something more fancy, then I just overwrite _format_table_field in table_controller.php. However, this does not work, giving me a "Fatal error: Call to a member function _format_table_field() on a non-object" (I tried CI_Controller->_format_table_field and Controller->_format_table_field too).

Does anybody have a suggestion as to how to solve this?


Messages In This Thread
Acces controller function from library / alternative work around? - by El Forum - 01-21-2011, 08:40 AM



Theme © iAndrew 2016 - Forum software by © MyBB