Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Explicitly refer a view in app/classes/views folder from a package
  • Hello,
    I'm developing an application with FuelPHP and I have the problem that I will try to explain below.

    I developed a package that contains several controllers. 

    These controllers are used (via inheritance) in controllers that are contained in the "app/classes/controller" folder of my application. 
    The controllers in the package use views that are defined in the package folder ("packages/mypackage/views").

    In one of the controllers of the app folder I need to override the default view set in the base class with a view that reside in the folder "app/classes/view".

    But when I try to use the view in the app folder I receive the following error:

    The requested view could not be found: viewname
    COREPATH/classes/view.php @ line 388


    I think that the framework searches the view in the package folder.

    So the question is: when I build a view, how can explicitly refer a view that is contained in the app folder, even if a controller is placed in a package?

    I hope I clearly explained the problem...

    Thanks for the help.


  • HarroHarro
    Accepted Answer
    If you haven't customized the finder's path other, the order of search is modules, app, packages, core.

    So if you have app/views/someview.php and app/packages/somepackage/views/someview.php, the one in app will be found before the one in the package.

    The reason for this is that modules are app extensions, and packages are core extensions. They are not designed to contain frontend stuff like controllers and views.

    You can explicitly load from a specific location (a module or a package) by using the namespace. So assuming in the example above the namespace of your package is "somepackage", you can load that using "somepackage::someview" as the viewname.

    This will only work for known namespaces, so the package must be loaded for it to work.
  • Hi Harro,
    based on what you said the current configuration should work.
    Maybe there is something I'm still missing. I will do some more check.

    Thank you very much.


  • why not loading the package over composer then you can use your namespace easily as the auto_loader will take care of his package namespace.
  • That doesn't really control loading a view file...

    From what I understand, the TS does:

    // app controller
    class Controller_Something extends \Some\Other\Controller
    {
       ...
    }

    // package controller
    namespace Some\Other;
    use View;
    class Controller extends \Controller
    {
        public function action_index()
        {
            // this should load from ./app/views, but doesn't
            return View::forge('someview');
        }
    }

Howdy, Stranger!

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

In this Discussion