Welcome Guest, Not a member yet? Register   Sign In
Not sure to migrate to CI4
#1

I developed dozen of website with CI3. During the last days, I try to migrate one of my site to CI4. 

I'll be frank with you, it appears to me as a huge job and I'm not sure to continue with CI4. Furthermore, my code size noticeably increased.

In my CI3 version, I had many redirections in helpers, libraries or models. With CI4, redirections can only be performed from controllers. It adds a lot of complexity to my controllers. A simple example : in models I request data from DB, if something goes wrong, the redirection was performed from the model with CI3. Now I have to add return parameters to check in the controller if a redirection is needed. Since it can't be done before or after the controller, filters doesn't help. 

In my BaseController, I check if the user is logged, so I always connect to the DB. In my models, I need a new connection, because I'm working with several tables and I can't use the $table attribute. The other option is to send the DB handler to the constructor of the model (same problem for the sessions by the way),  but my code becomes more and more complex. 

Previously, data from form was trimmed with form validation. It is no longer possible. I have to add new lines of code to trim posted data. 

I could provide many other examples like the previous ones, but globally, my code becomes really more complicated, and I do not understand the CI4 philosophy that will allow me to keep my code clean and concise as it was for CI3.

I also found the documentation not clear, I had to search many times on the forum, lot of information is missing or is unclear.

I'm sorry for this negative feedback, but I really love CI3 and I through it could help... unless it is a cry for help.
Reply
#2

(This post was last modified: 05-12-2020, 09:23 PM by bivanbi.)

I understand your struggle. When I first switched to CI4, I thought it would be a matter of few touch-ups and my application would work right away. Wrong.

But throughout upgrading - or better put, rewriting - my code base for CI4, my coding style changed for the better. It was totally worth it. Of course you could do it with any other modern truly object-oriented framework.

While I cannot give you specific advice as I have not used techniques like filtering yet, what sometimes helped me to simplify multi-table-operation is defining views and functions in database itself. Since models and entities per definition relate to a single table (or view, that is), I found myself creating higher order model and entity classes that simplified the operation of controllers by hiding the multi-table structure from the rest of the app.

I also have a faint feeling that your models might violate the single responsibility principle, if those models get to decide when and where to redirect the users, so it might help to re-think where you put that logic.
Reply
#3

(05-12-2020, 09:21 PM)bivanbi Wrote: I understand your struggle. When I first switched to CI4, I thought it would be a matter of few touch-ups and my application would work right away. Wrong.

But throughout upgrading - or better put, rewriting - my code base for CI4, my coding style changed for the better. It was totally worth it. Of course you could do it with any other modern truly object-oriented framework.

While I cannot give you specific advice as I have not used techniques like filtering yet, what sometimes helped me to simplify multi-table-operation is defining views and functions in database itself. Since models and entities per definition relate to a single table (or view, that is), I found myself creating higher order model and entity classes that simplified the operation of controllers by hiding the multi-table structure from the rest of the app.

I also have a faint feeling that your models might violate the single responsibility principle, if those models get to decide when and where to redirect the users, so it might help to re-think where you put that logic.

Thanks for the reply, I already made this analysis about my programming style, I'm conscious of it. My DB architecture is clean, I'm sure of that. The way I deal with it in the models my be improved but I have several DB, many tables in DB and lot of joints between tables and DB. It's easier for me not to spread out my code on many models. In fact my models are not table-related, but "concept"-related. A concept may deal with several DB / tables. 

My main concern is the redirection. In CI3, I created an alert library that creates a Flashalert in the session variable and redirect to a given page. This allow dealing with errors anywhere in my code from controllers, models, libraries or helpers). In CI4, I can't find a simple and convenient strategy to solve this problem.

My problem is not that I don't like or disagree with the new architecture. My issue is that I do not understand how to solve my problems and build a nice architecture that keep my code concise and maintenable.
Reply
#4

@imabot,
> During the last days, I try to migrate one of my site to CI4.

I was never a fan of migrating and would be tempted to rewrite. Start with the Welcome_message and gradually introduce portions of the old site.

CI4 is different and best to forget the old CI3 single main class bad habits and slowly learn how to use multiple classes. Initially the learning curve is quite steep but it does get better.
Reply
#5

(This post was last modified: 05-13-2020, 04:13 AM by imabot.)

(05-13-2020, 02:27 AM)John_Betong Wrote: @imabot,
> During the last days, I try to migrate one of my site to CI4.

I was never a fan of migrating and would be tempted to rewrite. Start with the Welcome_message and gradually introduce portions of the old site.

CI4 is different and best to forget the old CI3 single main class bad habits and  slowly learn how to use multiple classes. Initially the learning curve is quite steep but it does get better.

Thank you for the advice; I'm not a junior developer, I know exactly what you explained, I already did the tutorial, and I understand perfectly what I'm doing. The question is not really about me or migration, it's more about how to solve the problems I explained earlier with CI4.

I feel like if CI4 adds more problems than it helps. 

By the way, I use a PHP framework to win time, If I have to restart my work from scratch every time a new version is published ... Not sure it worths using a framework.
Reply
#6

@imabot
> . A simple example : in models I request data from DB, if something goes wrong, the redirection was performed from the model with CI3.

Can you give more details concerning "something goes wrong". and what action is taken?

I think this is the controller's job and the model is being used incorrectly. I think model should only request or perform actions on tables. Results should be returned to the controller which will decide the next action.

Helpers are only used to accept and return modified data.
Reply
#7

(This post was last modified: 05-14-2020, 10:24 AM by jreklund.)

(05-13-2020, 04:12 AM)imabot Wrote: By the way, I use a PHP framework to win time, If I have to restart my work from scratch every time a new version is published ... Not sure it worths using a framework.

I don't think this will happen every-time .. it just happened this one time from 3 -> 4 ,  which was known beforehand as CI matured to implement more modern practices.
Reply
#8

(This post was last modified: 05-14-2020, 08:17 AM by imabot.)

A simple example: some pages are restricted to some users, depending on the user rights. I need to load the page data before checking if the current user is allowed to visit the page. Filters are not great because I have to load and process the page data twice (once in the filter and once in the controller). Redirecting from models / libraries / helpers is no longer possible. So it must be done in controllers. The problem is that my controllers becomes more and more complicated. Even worse, I can't split my code into functions, because redirection in CI4 is based on return, so I can't redirect from a private method in my controller or BaseController. Do you get it?
Reply
#9

Pretty much migrating from CI3 to anything will require a rewrite. Im in the midst of migrating ci3 to symfony and it's a pain
Codeigniter is simply one of the tools you need to learn to be a successful developer. Always add more tools to your coding arsenal!
Reply
#10

I started some dev with symfony (latest) and i can tell you from my limited experience compared to symfony CI4 is a walk in the park !
CMS CI4     I use Arch Linux by the way 




Arch Book
Reply




Theme © iAndrew 2016 - Forum software by © MyBB