Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Autoloader with ViewModels
  • Hello,

    Having a minor issue with AutoLoading ViewModels.

    I'm trying to create a base ViewModel called Base_ViewModel that other viewmodels inherit from.

    I've created a folder in app ->classes -> view called "base" and created a file called viewmodel.php with the class declaration being the following inside the "base" folder:

    class Base_ViewModel extends ViewModel{

        public function view(){
            $this->header = View::forge("header");
            $this->footer = View::forge("footer");
        }

    }

    Unfortunately, other viewmodels inheriting from this Base_ViewModel get an exception:

    ErrorException [ Error ]: Class 'Base_ViewModel' not found

    Are the autoloader rules different for this scenario?

  • HarroHarro
    Accepted Answer
    No. The autoloader uses the 'classes' folder as the root of the cascading file system.

    So classes\view\base\viewmodel.php would contain a class called View_Base_Viewmodel. Or a class Base_Viewmodel in the namespace "\View". Or a class called "Viewmodel" in the namespace "\View\Base".

    Viewmodel classes are loaded from this folder because Viewmodel::forge() prefixes "View_" to the determined classname.

Howdy, Stranger!

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

In this Discussion