Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Parser problem with View location hardcoding
  • Hy guys,
    I'm working on Parser package improvements. I've some problems to get parser working with a View location hardcoding ( View::factory('module::view_name') ) for modules. Skeleton :
    ...
    - modules
     - test
      - classes
       - controller
        - test.php
      - views
       - test.php
    

    Controller code :
    // View call with location hardcoding
    $view = \View::factory(strtolower(__NAMESPACE__) . '::test');
    ....
    return $view->render();
    

    Error :
    Fuel\Core\Fuel_Exception [ Error ]: The requested view could not be found: ./test/test
    The problem I think is in /packages/parser/classes/view.php on line 28 :
    $file  = pathinfo($file, PATHINFO_DIRNAME).DS.pathinfo($file, PATHINFO_FILENAME);
    

    If you substitute this line with :
    $file = basename($file, '.'.$extension);
    

    works fine but you have a Fatal error on normal View call ( View::factory('standard_view') ) Any suggestion??
  • It's pretty stable but support for non-active modules hasn't been added yet, I'll take a look into the github issue soon.
  • Module view loading is supported through View::find_file(), which is utilized by the parser as well. I don't have any problem loading module views, direct or via the parser, as long as the module is loaded first. Did you add the module before you called it's view?
    \Fuel::add_package('parser');
    \Fuel::add_module('test');
    
    $this->response->body = \View::factory('test::test/index.php');
    
  • Ooops, I'm missed to specify that I called :
    // View call with location hardcoding
    $view = \View::factory(strtolower(__NAMESPACE__) . '::test'); 
    ....
    return $view->render();
    
    from module. In controller I specify :
    $widget = Event::trigger('test');
    

    And in module I wrote :
    <?php
    
    namespace Plugins;
    
    class Controller_Plugin1 {
    
     public static function init()
     {
      \Event::register('test', strtolower(__CLASS__) . '::test');
     }
    
     public static function test()
     {
       $view = \View::factory(strtolower(__NAMESPACE__) . '::test');
       //$view = \View::factory(strtolower(__NAMESPACE__) . '::test.twig');
       //$view = \View::factory(strtolower(__NAMESPACE__) . '::test.mustache');
       //$view = \View::factory(strtolower(__NAMESPACE__) . '::test.stags');
       //$view = \View::factory(strtolower(__NAMESPACE__) . '::test.dwoo');
    
       $view->variabile = 'Whoooaaaaaa!';                
       return $view->render();
     }
    
    }
    

    and then I getting this error :
    http://i.imgur.com/7CojS.jpg
  • I'm still clueless to where the './plugins/test' comes from. That even happens when you hard-code 'plugins::test'? What PHP version are you using? What platform? I've tested the result of the pathinfo() calls in the parser here, but on my dev system it leaves the double colon alone...
  • There's a lot of confusing ... my fault, sorry.
    I've updated file names for testing and now update you for new skeleton. Skeleton :
    app
       ...
       - modules
        - plugins
          - classes
            - controller
               - plugin1.php
          - views
            - test.php
    
    That even happens when you hard-code 'plugins::test'?
    Yes I'm using PHP 5.3.5 on Apache 2.0
    Fuel ver. 1.0 rc3 with last version of parser library
  • Fixed, it was indeed the pathinfo() that was behaving funny...
  • It works!! :-D Thank you WanWizard!!!!!!
  • Haven't looked at Parser, and I'm not sure what the current state of the project is. Maybe Jelmer can comment...

Howdy, Stranger!

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

In this Discussion