Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Modules: what am I doing wrong here?
  • The code below is giving me the following error : ErrorException [ Error ]: Class 'template\View' not found with this line causing the error:
    $this->response->body = View::factory("stripes/index");
    This is the code inside modules/template/classes/controller/template.php and there is some random text in modules/template/views/stripes/index.php
    <?php
    
    /**
     * Module controller in the Mymodule module
     */
    
    namespace Template;
    
    class Controller_Template extends \Controller&#123;
    
     /**
      * The index action.
      * 
      * @access  public
      * @return  void
      */
    
     public function action_index()
     &#123;
      $this->response->body = View::factory("stripes/index");
      
      //$this->render('stripes/index');
     }
     
     public function action_hello()
     &#123;
      $this->response->body("hello");
     }
    
        // put your controller code here, just like for an application controller
    }
    

    action_hello works just fine from the url: .../index.php/template/hello
  • Exactly what the error message says: "Class template\View not found". If you're using View::something inside a namespaced class, you're calling the class in that namespace. And if that doesn't exist, PHP will complain about it. In modules, if you want to access core classes, load them from the global namespace by prefixing them with a backslash.
  • Thanks, controller updated as follows, with a backslash in front of view:
    <?php
    
    /**
     * Template Module Controller.
     *
     * A module to manage templates
     * 
     * @extends  Controller
     */
    
    namespace Template;
    
    class Controller_Template extends \Controller
    
     /**
      * The index action.
      * 
      * @access  public
      * @return  void
      */
     public function action_index()
      $this->response->body = [u]\View[/u]::factory("stripes/index");
     }
     
     public function action_hello()
      $this->response->body("hello");
     }
    }
    
    /* End of file welcome.php */
    

Howdy, Stranger!

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

In this Discussion