Welcome Guest, Not a member yet? Register   Sign In
Calling controller methods from inside view
#4

[eluser]gtech[/eluser]
I don't see anything wrong in your approach metaltapimenye,

you don't have to put the method in the constructor.

you can just as easily do:

Code:
function index(){
    $data=array();
    $data['title'] = $this->_title();
    $this->load->view('viewname',$data);
  }
  function _title(){
    return "hello";
  }

you would be achieving the same thing. because all you were doing is executing the function in the controller constructor and then making the return data available in the view.

maybe if you were doing this approach you could prefix the function with an _ so that you cant browse to the function. If you are calling the function everywhere its best to move it to a library or a helper (or create a base controller you can extend from).

you may be able to pass the function reference to the view.. $data['function'] = & $this->_title(); but I think that is just yuck!


Messages In This Thread
Calling controller methods from inside view - by El Forum - 05-29-2008, 04:07 PM
Calling controller methods from inside view - by El Forum - 05-29-2008, 04:31 PM
Calling controller methods from inside view - by El Forum - 05-30-2008, 05:12 AM
Calling controller methods from inside view - by El Forum - 05-30-2008, 05:33 AM
Calling controller methods from inside view - by El Forum - 05-30-2008, 07:04 AM
Calling controller methods from inside view - by El Forum - 05-30-2008, 07:20 AM
Calling controller methods from inside view - by El Forum - 05-30-2008, 07:28 AM
Calling controller methods from inside view - by El Forum - 05-30-2008, 07:50 AM
Calling controller methods from inside view - by El Forum - 05-30-2008, 07:57 AM
Calling controller methods from inside view - by El Forum - 05-30-2008, 08:40 AM
Calling controller methods from inside view - by El Forum - 05-30-2008, 08:53 AM
Calling controller methods from inside view - by El Forum - 05-30-2008, 09:05 AM
Calling controller methods from inside view - by El Forum - 05-30-2008, 09:15 AM
Calling controller methods from inside view - by El Forum - 05-30-2008, 09:21 AM
Calling controller methods from inside view - by El Forum - 05-30-2008, 10:45 PM
Calling controller methods from inside view - by El Forum - 05-20-2012, 05:38 AM
Calling controller methods from inside view - by El Forum - 05-20-2012, 06:22 AM



Theme © iAndrew 2016 - Forum software by © MyBB