tags:

views:

46

answers:

1
public function test(){
        $data = ORM::factory('testdata')->find_all();

        Table::factory()
            ->set_body_data($data)
            ->set_row_titles('id')
            ->set_column_titles(Table::AUTO)
            ->set_callback('format_row', 'row')
            ->render(true);

            $this->template->title = '';
            $this->template->payment_content = '';
    }

    function format_row($row, $index){
        if ($index % 2 == 0) return new Tr('', 'zebra');
    }

// getting an error : callback function format_row does not exist!, both methods declared in a controller class (Payment_Controller)

how do I do callbacks in MVC?

+2  A: 

If format_row() also belongs to the class where the test() method is, then the callback should be passed as array($this, 'format_row'). So, perhaps you should change the line 7 of test() to ->set_callback(array($this, 'format_row'), 'row').

Ignas R
However, it has nothing to do with whether you're using MVC or not...
Ignas R
how would I do it if the callback is in another controller class, say in a class declares as Main_Controller
Ygam
Then, `array(new Main_Controller, 'format_row')` if it's an instance method, or `array('Main_Controller', 'format_row')` if it's a static one.
Ignas R
thanks! I was looking to implement this in Kohana because my callbacks for checking if a field is already existing is defined in the controller thus forcing me to use $this when I could have called the class responsible for looking up entries! thanks a lot!
Ygam