views:

95

answers:

1

I am trying to find out how can I used PHP interfaces in my MVC design. I want to make sure that the design enforces an interface so that any new module would follow that.

For example:

<?php

interface BaseAPI {
     public function postMessage($msg);
}

class ServiceAPI implements BaseAPI {
     public function postMessage($msg) { return $msg; }
}

class Service_Two_API implements BaseAPI {
     public function postMessage($msg) { return "can't do this: ".$msg; }
}

?>

I want to do this in CI. Is it possible? how should I design it?

+1  A: 

Depends on what you're asking. If you're asking if you can make the Code Igniter framework follow your Interfaces, you could, but it would require a whole lot of refactoring in their framework, and probably wouldn't be worth the work.

If you're asking if you can add Interfaces for your custom classes while using Code Igniter, of course you can. CI doesn't limit your ability to create custom code, in fact that's what it's there for. I guess the real answer is "What exactly are you asking?".

EricBoersma