Welcome Guest, Not a member yet? Register   Sign In
Help to apply onion architecture in codeIgniter

I'm not saying it's not good idea.

It's a trade-off between getting project going quickly, using tools that framework has provided, or having to write your own layer for cross layer communication to stay completely framework independent.

For you that independency might be most important measurement for codebase, while for me, I am more concerned with quick results, so I'm ok relaying on framework tools and libraries. Neither approach is wrong, but it has to be right approach for each individual project.

Is this your first MVC project?

I've seen couple of tutorials out there, but to be completely honest, unless you start working on an actual project, it's very hard to grasp the concept from just reading tutorials. I'd say there's nothing better than getting your hands dirty and doing a little mock project first, if you don't want to commit to a framework just yet.

I am coming from Java. I want just to apply the technique that shows the pdf Clean architecture. In page 97 implement that technique in the Zend framework. But I cannot do the same things in CodeIgniter. I prefer to stay Independence from framework because I want to concentrate in the business logic. I cannot find any tutorial in clean architecture for Codeigniter. I found only for symphony. Also Codeigniter don't support Depedency Injection(I think!).

For dep injection, you should be able to do, more or less on both 3 and 4:
CI3 - https://forum.codeigniter.com/post-334318.html
CI4 (old article, but presumably it hasn't changed that much) - http://blog.newmythmedia.com/blog/show/2...eIgniter_4

For CI4 it'll be available for core level (aka DB and what not).

If you already have Java MVC experience, it might make it easier, because you already know the principles, or harder, because essentially PHP and Java work completely different to each other.

Effectively it's all about what code you put in models and what code you put in controllers, no?

Any framework you use will have dependencies somewhere, especially when it comes to the database. When aiming for framework independence as much as possible, don't forget the Repository pattern. I think that works great with either of the development ideologies mentioned. It keeps the model on in the Repository class so the rest of the application can rely on a consistent API through the Repository. If your framework changes, or your storage engine changes, update the methods in your repository class and you're good to go. That's very simple to do in CI4.

I think people often confuse Dependency Injection with a Dependency Injection Container. You can use DI (to some extent or another) in any framework. Many frameworks will provide a DI Container, though, that does the behind-the-scenes magic of locating the class and inserting it for you. That's a convenient thing, for sure, but also ties you a framework whose DI container operates the same way the current one does. I think the CI4 solution, while not as magical, actually ties you to the framework less than a container, since it's just a simple class that holds functions that create the stuff for you. While a base Services class might have to be copied over and given a different namespace, it's a transparent class with few, if any, ties to the framework.

Controllers will very often be tied heavily into the framework. That is very difficult to get away from, but it does mean you can limit your direct framework dependence to the Controller in many cases, especially if you have layers, like Repositories, that insulate you from the model.

Which brings me to my last point about framework independence. You can never get away from dependence on the framework 100%. Even if you don't use one of the named frameworks and you build your own from packages loaded from Composer - you've just built your own framework that are dependent on. The best you can do is to find ways to help insulate your core code and help make changes simpler. That said - radical changes like moving from one framework to another are pretty uncommon in my experience and is going to be a painful experience no matter how much you insulate yourself. So maybe just get coding, do your best to insulate yourself with the knowledge you have currently, and get better each site you make until you have a set of patterns you and your team like and does what you need it to do.

Theme © iAndrew 2016 - Forum software by © MyBB