Jump to content

PHP OOP Inheritence from different directory


JeremyTiki

Recommended Posts

Ok so I'm trying to make a small framework for personal needs, just to speed up small project time.

 

My biggest issue right now is I want all the controllers in my application to inherit from one class the "skel_controller" but it needs to stay in a different directory. The directory structure looks like this

/root

  /app

      /application

        controller_for_app.php

  /libs

      /skel

        skel_controller.php

 

Can anyone help me with this?

Link to comment
Share on other sites

Easiest thing to do would be to either

 

1) add the path corresponding to your /root to the include_path setting for php, then you can just add a require_once 'libs/skel/skel_controller.php' to the top of your controllers or

2) Setup auto-loading and let that take care of including any classes when needed.  Then you don't have to worry about making sure you have all the necessary require directives in your class files, php will load the class when on-demand.  One of the easiest ways to handle auto-loading is to use namespaces and make each namespace level a directory.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.