Welcome Guest, Not a member yet? Register   Sign In
Design Pattern examples?
#1

[eluser]Unknown[/eluser]
Since OOP usually involves abstracting responsibilities from a huge class to many smaller classes, I was wondering how I could implement this to CI.

Say we have a Document class, and an Email class, we want to both to implement a Write interface. How would we do this with CI?

A background about my level of understanding OOP. Not really deep, most information are read online and through books, but hardly implemented one.
#2

[eluser]jjDeveloper[/eluser]
Codeigniter uses the MVC design pattern so study up on the principles of that pattern then read how it applies to CI in the documentation.

here is a subclass in ci

Code:
class YourController extends CI_Controller {

  public function __construct() {
    parent::__construct();
    $this->load->library('your-document-class-name');
    $this->load->library('your-email-class-name');
  }

  public function Index() {
    $this->your-document-class-name->classFunction($someData);
    $this->your-email-class-name->classFunction($someData);
  }
}

or put the class in the core folder and extend CI_Controller

Code:
class someController extends MY_YourDocumentClassName {
    public function Index() {
      $this->subclassFuntion($someData);
    }
}

I would suggest going over the documentation thoroughly as it is jam packed with information regarding this.
#3

[eluser]PhilTem[/eluser]
You can of course write an interface for the Write-class/interface which your 'document' and 'email' class implement. There are no restrictions for creating 'standard' OOP in PHP with CI. I'd suggest you just write it like you weren't using CI and then make the changes to the classes so it can use e.g. the CI super-object or the global DB-variable or global CFG-variable.

I think I have seen some CMS' for CI that have some libraries using this interface-technique. But I don't find them at the moment anymore. If I run over them I will post some links here (the CMS' I look at most to get inspired are PyroCMS and Bonfire).




Theme © iAndrew 2016 - Forum software by © MyBB