Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Change view in ViewModel
  • If I have a ViewModel called View_Test but I want to load the view views/tests/filename how would I achieve this? I looked at the documentation and set $this->_view to my new filename, and call $this->set_view() and it works, but it also still looks for the views/test file as well.
  • If it's permanent you have to set the $_view in the class body:
    class View_Example {
        public $_view = 'something/else';
    }
    

    Or you overwrite the set_view() method to return something else, needs to change the $this->_view property to a View object though. (or at least an object that you can set properties upon and can be cast to a string)
  • so in my ViewModel I put the following: public function set_view($file) {
    $this->_view = \View::forge($file);
    } and then call that from my view method?
  • The Viewmodel class processes the view to be loaded in it's constructor, so there's not a lot you can do there since it either loads the defined view, or it automatically determines the view name if none is specified. In all cases, it then calls set_view() to load the view. That's why Jelmer suggests to add a set_view() method to your Viewmodel class. Simply ignore the $file parameter passed, add your own logic to the method to determine which view to load, and assign it to $this->_view.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion