SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    Join Date
    Mar 2005
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Creating plugins with shared base class

    Before I get started describing my question, I need to make the normal disclaimer. I'm a rookie when it comes to PHP OOP.

    I'm working on creating an AJAX / PHP based dashboard / portal application for the organization I work for. The page will be made up of many different widgets or plugins that are specified / configured via a user control panel.

    My original plans were to create a base class that looked something like the following:

    PHP Code:
    class dashboardObject
    {

       protected 
    $isConfigurable;
       protected 
    $instName;

       function 
    __construct($oid) { ... }
       ...
       public function 
    fetch();


    At runtime, I would instantiate a user specifyable number dashboardObjects, specifying the details of the object via an object id. The object id would be linked to a database table that specified the object (extender) type and any user preferences associated with the specific instantiation of the object. The object type would somehow point to the appropriate class that extends my base class.

    Unfortunately, I've searched through most of the PHP documentation, and can't find an elegant way to specify which extender class to use at the time of the base object creation. I can think of many ways to hack something together, such as using the eval function or a hardcoded if tree, but I'm guessing there is a more elegant way to approach the problem

    Does the above explanation make sense? Is there a better approach to solving my problem? Any feedback would be helpful.

    Thanks

  2. #2
    SitePoint Addict timvw's Avatar
    Join Date
    Jan 2005
    Location
    Belgium
    Posts
    354
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    meaby i don't get what you are trying to say, but what is wrong with?

    PHP Code:
    interface base {
      function 
    doStuff();
    }

    class 
    concrete implements base {
      function 
    doStuff() {
        echo 
    "who's your daddy?";
      }
    }


    $name "concrete";
    $object = new $name;
    $object->doStuff(); 
    Offcourse you can use introspection etc to find out if the $object is really a "base" object... and/or if the method doStuff is available...

  3. #3
    SitePoint Member
    Join Date
    Mar 2005
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That answered my question. I didn't know that you could say $object = new $variable;

    Thanks for your help.

  4. #4
    SitePoint Addict
    Join Date
    Mar 2005
    Posts
    246
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by utklwg
    I'm working on creating an AJAX / PHP based dashboard / portal application for the organization I work for. The page will be made up of many different widgets or plugins that are specified / configured via a user control panel.
    Hello,
    Just wondering if you have completed your dashboard application?

    I have also been looking for a PHP/MySQL dashboard solution.

    I have seen the Dashboard integrated into www.sugarcrm.com and would be great if someone could make a standalone application from it - so users could map their own database fileds?

    Best wishes,

    - Vince


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •