New portal site

New portal site

I’m attempting to create a new portal framework to drastically simplify the presentation of news and student specific information. This is currently handled by Drupal with various inhouse modules hanging off it.

Part of this is a news manager which will be able to supply federated news feeds as well as plain HTML to various sources.

I’ve decided to use php interfaces throughout the development as this is seen as best practice (at the moment). There’s a main class for the site which provides bread and butter information such as the current pageid, who the logged in user is etc.

In php you define your interface like this:

interface iLearnnet {

    public function get_content($pageid);
    public function get_page_id();
}

This is truncated as there are quite a lot of functions. Each function defined here will be implemented in the class:

class InterfaceClass implements iLearnnet {

    public function get_content($pageid) {
        // do something useful and return the content
    }
    public function get_page_id() {
        // return the page id somehow
    }
}

You don’t have to know how the implementation will work in order to define it as ‘something the site can do’. This is useful for getting the abstraction right before you settle in to actually work out how to implement things. Functions here would get quite big and the interface unweildy so I break out more complex functions into an interface_functions.php file. So if get_content ends up being more than 50 or 60 lines I’ll just use a kind of dummy call to a larger function in another file (a bit like code behind files in ASP.NET).

   public function get_content($pageid) {
   
        $contentarray=array();
        $contentarray=get_content_array($pageid); 
        return $contentarray;

    }

To actually use the interface all you need to do is instantiate an instance of the class and start accessing it’s functions:

$learnnetobject = new InterfaceClass(); // class InterfaceClass implements iDumgal
$pageid= $learnnetobject->get_page_id();
$pagecontent= $learnnetobject->get_content($pageid);

Now you have the ID of the current page and an array with the page content in it which you can work with.

Leave a Reply

Your email address will not be published. Required fields are marked *

For security, use of Google's reCAPTCHA service is required which is subject to the Google Privacy Policy and Terms of Use.