Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
base class is not working
  • hello i got a error when im using a common controller in subdirectory of controller
    For eg
    all inside controller
    controllers/backend/common.php
    class Controller_Common extends Controller_Template{
    //something goes here
    }
    
    again another class
    controllers/backend/post.php
    class Post extends Controller_Common{
    }
    ErrorException [ Error ]: Class 'Controller_Backend' not found
    
    but it works fine when i am not using this inside subdirectory(i.e.)
    control
    contoller/posts.php
    controller/common.php
    Is this a bug or i need to do more configuration. I have one more question. what is bootstrap file and how to use it to create a simple package.I am using the self classes which i put in classes directory.Somewhere in the forum i read that packages will be easy to manage than the class.so please help me in this issuees. any sugesstion will be appreciated
  • They need to be full paths
    class Controller_Backend_Common extends Controller_Template{
    

    Not I added backend to the class name.
  • No problem :)
  • Again i encountered with certain problem
    class Post extends Controller_Common{ 
     public function __construct() {
            parent::__construct();
        }
        
        function action_index(){
            $this->template->title="Welcome Admin";
            $this->template->content=View::factory('admin/index');
        }
    }
    ErrorException [ Error ]: Call to a member function body() on a non-object
    
    COREPATH/classes/controller/template.php @ line 56
    
  • Why are you overwriting the __construct() method? You're disabling an important part of Fuel's application flow by doing this, thus causing your error. EDIT
    There's actually a warning about this in the latest version of the docs which isn't yet on the website:
    Don't overwrite the class constructor __construct(), use before() instead. Unless you have studied the base Controller from the Core first and understand how it must be extended not to break Fuel.
  • Thanks its solved.Cant we use constructor in any part of the application?
  • Of course you can use it, the Controller is an exception though because it needs to extend its base controller constructor exactly in order to get both the Response & Request objects set on it. You can still do it, but as I quoted from the latest docs: only if you know what you're doing by replacing it. The before() method is used instead of the constructor for this reason.
  • class Controller_Post extends Controller_Common {
        // Code here.
    }
    

    Be sure to properly name your classes.
  • thank you. it helped to know me about many things
  • it helped to know me about many things

    42... and now you know everything :P

Howdy, Stranger!

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

In this Discussion