Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Using Parser on ViewModel
  • Let me start off by saying I have searched for this, but I am unable to find anyone else experiencing the same problem. Due to this I might just be retarded and missing the point so if that is the case please point that out to me. :) I am using the default controllers, models, and views provided from a fresh extract of the latest version of FuelPHP. I am however just simply trying to get the parser to work. The function "hello" in the "welcome" controller is using the ViewModel as shown below:
    return Response::forge(ViewModel::forge('welcome/hello'));
    

    When i try changing that to welcome/hello.mustache I get an error. I also tried changing the mustache library extension to php which also did not work. Is there any way to get the ViewModel to also parse the views?
  • If you load the parser package, it wil extend the core View class to support your choice of parser. The Viewmodel will use \View() from the global namespace, so it should use the one extended by the parser package. I never had any issue with this. In other words, if \View::forge('yourview.mustache') works, so would \Viewmodel::forge('yourview.mustache'). If it doesn't, there is an issue with the parser which needs to be sorted first.
  • I had this same problem when trying to use the mustache parser for templates. The fix for me was to add this to my ViewModel: public $_view = 'hello/world.mustache'; And then I can call the ViewModel in the standard way with: ViewModel::forge('hello/world'); (no ".mustache" extension because it is using this string to load the ViewModel class not to find the template file.) Many thanks to FrenkyNet|work on IRC for working this out for me.
  • From my tests it seems as if the parser required an extension to actually parse the view. Now if I have code like this:
    ViewModel::forge('welcome/hello.php');
    

    I get an error like this:
    OutOfBoundsException [ Error ]: ViewModel "View_Welcome_hello.php" could not be found.
    
  • I believe this should be corrected. I've created an issue for it: https://github.com/fuel/core/issues/1034
  • Viewmodel::forge() doesn't load a view, it loads a viewmodel class. It is the viewmodel class that defines the view to load. This is documented here: http://docs.fuelphp.com/general/viewmodels.html

Howdy, Stranger!

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

In this Discussion