Welcome Guest, Not a member yet? Register   Sign In
MVC with Mapper-Class
#1

[eluser]htheus[/eluser]
Hi everyone

I am kinda a CI-Newbie. My question is: Anyone is using Mapper-Classes with CodeIgniter?
My "basic OO-architecture with Mapper-Classes" would look like this:


- FrontController: index.php uses a FrontController which loads another spcific Controller (contact, about me, etc)

- Controller: Every specific controller implements the domain logic (business logic). The controller loads the specific Mapper-Class (not the Model!).

Example: $myMapperObj = new UserMapperObj("{$model_name}");

- Mapper (additional layer): It's main task is to map data (any kind of source) on an object. The abstract SuperClass Mapper() loads the module $module_name. The specific Mapper-Class implements its and so inherits also the instance of the model class. The specific Mapper-Class implements the use-cases specific querys like getOverview(), getLastVisitors(), etc.. The Mapper-Class returns an mapped object.


- the Model implements the _set() and -get()-Methods plus __construct() ONLY and represents the abstraction layer between the data source and the application itself (In case that the data source is a MySQL-DB, the Model inherits all methods of the CodeIgniter-Database Class).

- View: The Controller sends the necessary data (MappedObject) to the view

Any idea to improve that architecture? Or anyone has a better idea to integrate Mappers ;-) ? Is there any best practice for CI?

Thx in advance for your replies.
Greetings from Zurich!


PS: Sorry for my bad english Smile
#2

[eluser]WanWizard[/eluser]
There are several data mappers available for PHP, and some specific for CI. They all work slightly different, so you'll have to check them out and see which one works for you.

I mentioned some in my CICONF talk, see http://lanyrd.com/2012/ciconf-uk/sqbyd/#link-gycg for the slides.

CI doesn't support a front controller architecture out of the box, as it uses a singleton pattern for all classes, including the controller. There is no mechanism to call secondary controllers. There is a 3rd party solution available called "Modular Extensions HMVC" which does some in that area, but it being an add-in, you miss proper integration.
#3

[eluser]htheus[/eluser]
Hi

Thx for the link ... very helpful informations Smile

Greetings

han




Theme © iAndrew 2016 - Forum software by © MyBB