Welcome Guest, Not a member yet? Register   Sign In
Thoughts on extending CI architecture with a dedicated data layer
#1

[eluser]Unknown[/eluser]
Hello! I am fairly new to CodeIgniter and this far I really like it. However, I'm thinking about extending the framework with some things I find nice to have in an MVC application. I will present my ideas here in hope of getting some input from more experienced users of the framework.

First of all, I would like to add a new layer to the architecture. This layer would be responsible for all persistence logic, so, basically a "data layer". I have seen people using the Models in CI to fetch data and I really don't like to use MVC like that. My belief is that each view should have its own model, only containing the data needed in that specific view. Controllers would handle communication with the data layer, parse the raw data (maybe returned in shape of a domain model object?) retrieved into a viewmodel and then finally send the viewmodel to a view.

Things to discuss:

1) Where would I put this "layer" in relation to the CI framework? I would still like to use the database stuff currently available in CI.

2) How would this layer interface with the MVC application? My idea is to have repository classes and a domain model representing the database structure. Controllers would have access to the repositories and use the instances of them for CRUD. Imagine something like this:

Code:
//create repository
$userRepository = new UserRepository();

//fetch data
$user = $userRepository->GetById(1);

//insert data
$newUser = new User(/* whatever data you fill the user with */);
$userRepository.Insert($newUser);

Each repository could implement an interface with the necessary CRUD operations available. SQL for fetching data, including joins and all that, would be in the classes implementing the interface.

This is the basics of my idea. Further details on how to implement this can be discussed later on if you find it interesting. I have quite a lot of ideas but I don't want to start the discussion with a wall of text.

So.. What do you think? I'm not sure if managed to communicate the idea properly, please ask for clarification if needed.

Have a nice weekend!




Theme © iAndrew 2016 - Forum software by © MyBB