Welcome Guest, Not a member yet? Register   Sign In
10 abnormalities in CodeIgniter that everyone should know
#1

[eluser]Buda[/eluser]
Hi everyone. I was hired by a company to refactor one of their main systems built on top of CI. I spent 3 months fixing CI bugs and re-designing the entire architecture of the framework. I was quite shocked to find out so many abnormalities and design errors.

Here's a list of the ones that I consider critical and I think everyone should be aware of:

1. 90% of the system is written in PHP 4, a deprecated version of the language.

2. The framework doesn't have a Front Controller. Strangely, the application controller becomes the Front Controller, this means that the framework can only load one controller at a time (per request).

3. The CodeIgniter/CodeIgniter.php file is not a class, it should be part of the bootstrapper file, index.php.

4. MyController > Controller > CI_Base. There's no point of having 3 levels of inheritance. The only purpose of CI_Base is to return a single instance of the Controller, so it should be part of the Controller.

5. Namespaces: The Controller class doesn't follow the naming convention, it's not prefixed with CI_ like the rest of the core classes. This makes CI's namespace support very unreliable.

6. The application controller acts as a Front Controller and Registry, it's used to stores all the objects the framework needs.

7. Circular reference: When the Front Controller (App. Controller) loads a model, the framework assigns to the model all the object properties of the Front Controller. This is the most obscure behaviour I found in CI.

8. The router.php file contains an array that uses the keys to store data and define regular expressions. If you define 100 elements, the Router class will loop through the entire array, extract the keys and execute 100 regular expressions.

9. Common.php is not a class, it should be moved to the helpers/ directory and renamed to something more appropriate, like mvc_helper.php for example.

10. Very poor OOP and almost no design patterns makes this framework very difficult to extend and maintain.

Hope this helps,

Buda
#2

[eluser]Référencement Google[/eluser]
Unstead of rewriting CI, you should move to Kohana: http://www.kohanaphp.com
Your friends are waiting you there... >Sad
#3

[eluser]fdog[/eluser]
Seriously though, you'll love Kohana and its community. Their main developers feel pretty much the same way about CI and have already "fixed" most of its "abnormalities".
#4

[eluser]Buda[/eluser]
What's Kohana, is it a legacy of CI? Which of the 10 issues listed above does Kohana handle differently?
#5

[eluser]fdog[/eluser]
I think that's a topic to be discussed in Kohana's forum.
#6

[eluser]bijon[/eluser]
Hi buda ,
This is a nice issue you are foucusing.I am a CI fan . I dont want to switch from CI to other framework. I hope in the next version of CI may be CI 2.0 this issued are should be resolved. Because PHP 4 is died almost. Also there should be support naming conventions.

Thanks
http://saidur.wordpress.com
#7

[eluser]xwero[/eluser]
[quote author="Buda" date="1205560725"]1. 90% of the system is written in PHP 4, a deprecated version of the language.[/quote]
If you are going to support php4 and want to have the smallest code base you write in php4 because php5 is backward compatible? How would you create a version independent codebase?
[quote author="Buda" date="1205560725"]2. The framework doesn't have a Front Controller. Strangely, the application controller becomes the Front Controller, this means that the framework can only load one controller at a time (per request).[/quote]
How many controllers do you need per request?
[quote author="Buda" date="1205560725"]3. The CodeIgniter/CodeIgniter.php file is not a class, it should be part of the bootstrapper file, index.php.[/quote]
Can't it be because they want to keep the the actual framework code together? If you don't want to load the default codeigniter file you could make a custom one and load that in the bootstrap file instead of creating different bootstrap files.
[quote author="Buda" date="1205560725"]4. MyController > Controller > CI_Base. There's no point of having 3 levels of inheritance. The only purpose of CI_Base is to return a single instance of the Controller, so it should be part of the Controller.[/quote]
Maybe this is a window to improve the framework?
[quote author="Buda" date="1205560725"]6. The application controller acts as a Front Controller and Registry, it's used to stores all the objects the framework needs.[/quote]
I agree there should be a registry to store different objects in their own realm.
[quote author="Buda" date="1205560725"]7. Circular reference: When the Front Controller (App. Controller) loads a model, the framework assigns to the model all the object properties of the Front Controller. This is the most obscure behaviour I found in CI.[/quote]
Why is this bad?
[quote author="Buda" date="1205560725"]8. The router.php file contains an array that uses the keys to store data and define regular expressions. If you define 100 elements, the Router class will loop through the entire array, extract the keys and execute 100 regular expressions.[/quote]
If a match is found the loop stops.
[quote author="Buda" date="1205560725"]9. Common.php is not a class, it should be moved to the helpers/ directory and renamed to something more appropriate, like mvc_helper.php for example.[/quote]
It will be for the same reason as the codeingiter.php file to keep the framework code together.
[quote author="Buda" date="1205560725"]10. Very poor OOP and almost no design patterns makes this framework very difficult to extend and maintain.[/quote]
How is it difficult to extend the framework the forum is filled with extensions.
#8

[eluser]thurting[/eluser]
[quote author="xwero" date="1205571873"]
If you are going to support php4 and want to have the smallest code base you write in php4 because php5 is backward compatible? How would you create a version independent codebase?[/quote]
You wouldn't. You would just make it PHP5.

[quote author="xwero" date="1205571873"]
How many controllers do you need per request?[/quote]
One never knows. But there are plenty of use cases for forwarding to another controller action or needing to call multiple actions. Extending CI to do this would not be difficult.

[quote author="xwero" date="1205571873"]
Can't it be because they want to keep the the actual framework code together? If you don't want to load the default codeigniter file you could make a custom one and load that in the bootstrap file instead of creating different bootstrap files.[/quote]
For security reasons, index.php should contain as little code as possible. I think the current implementation is correct in this regard.

[quote author="xwero" date="1205571873"]
Maybe this is a window to improve the framework?[/quote]
It would be easy to make a singleton in PHP5. Even better to have a proper front controller as singleton that dispatches to action controllers.

[quote author="xwero" date="1205571873"]
I agree there should be a registry to store different objects in their own realm.[/quote]
Easy to do. A registry should be a singleton, so again, PHP5 is best here.

[quote author="xwero" date="1205571873"]
Why is this bad?[/quote]
It eats up resources.

[quote author="xwero" date="1205571873"]
If a match is found the loop stops.[/quote]
If a match isn't found, it doesn't. Who has 100 routes though? Still, regex eats up resources.

[quote author="xwero" date="1205571873"]
It will be for the same reason as the codeingiter.php file to keep the framework code together. [/quote]
The architecture could be better.

[quote author="xwero" date="1205571873"]
How is it difficult to extend the framework the forum is filled with extensions.[/quote]
An improved architecture would def. make the framework more user friendly.
#9

[eluser]xwero[/eluser]
[quote author="thurting" date="1205585255"][quote author="xwero" date="1205571873"]
If you are going to support php4 and want to have the smallest code base you write in php4 because php5 is backward compatible? How would you create a version independent codebase?[/quote]
You wouldn't. You would just make it PHP5.[/quote]
May i be a little evil now? If you have a business and you run 50 sites on php4 economics come before technology. You are not going to change the code to php5 because someone says hey php4 is death. 50 sites means many hours without making money. The move will happen but technology business is not as fast as the technology it runs on because they have to put food on the table.

[quote author="thurting" date="1205585255"]
[quote author="xwero" date="1205571873"]
Maybe this is a window to improve the framework?[/quote]
It would be easy to make a singleton in PHP5. Even better to have a proper front controller as singleton that dispatches to action controllers.
[quote author="xwero" date="1205571873"]
I agree there should be a registry to store different objects in their own realm.[/quote]
Easy to do. A registry should be a singleton, so again, PHP5 is best here.
[/quote]
You can have a singleton in php4, that is a false reason to move to php5.

[quote author="thurting" date="1205585255"][quote author="xwero" date="1205571873"]
Why is this bad?[/quote]
It eats up resources.
[/quote]
If i'm not mistaken the properties are added by reference so it doesn't eat up resources.

[quote author="thurting" date="1205585255"][quote author="xwero" date="1205571873"]
If a match is found the loop stops.[/quote]
If a match isn't found, it doesn't. Who has 100 routes though? Still, regex eats up resources.[/quote]
What would be a better way to have custom routing?

[quote author="thurting" date="1205585255"]
[quote author="xwero" date="1205571873"]
It will be for the same reason as the codeingiter.php file to keep the framework code together. [/quote]
The architecture could be better.

[quote author="xwero" date="1205571873"]
How is it difficult to extend the framework the forum is filled with extensions.[/quote]
An improved architecture would def. make the framework more user friendly.[/quote]
Ok CI is not the perfect framework. Use the framework you feel most comfortable with. About the user friendliness of the framework, there are many people who come from different backgrounds and even other php frameworks that find CI easy to use. i think that is all that needs to be said.
#10

[eluser]Buda[/eluser]
@xwero,

If your sites are using PHP 4, that's fine, no need to upgrade, move to a different server or refactor the code. But if you are still developing using version 4, that's very irresponsible and unprofessional, considering that you are selling to your clients a software developed using an obsolete technology. Also, my post it's not about "upgrade to php5", it's more about "you can improve some aspects of the framework you are using".

@thurting

Thanks, I think you answered some of xwero's questions up there.

Being able to call multiple controllers, to handle different types of request and forward them, is the basics of any framework and the first step to achieve true modularity.

php4 and php5 is not about singletons, is about quality assurance, performance, scalability. A clear example is CI's Model class, when instead of using the __get to check if a class member exists, it loops through the Controller's object properties and assigns them to the model. So if you load 10 models, you'll end up having 10 Front Controllers, 10 Registries and 10 Models. That's wrong, and it's a very serious issue, because it leads to circular reference and makes the system very difficult to debug and maintain.

Quote:Ok CI is not the perfect framework. Use the framework you feel most comfortable with.

Again please, don't get me wrong, I'm not here to compare or talk about other frameworks. I don't use CI, but you do. So this might help you (and other developers) understand a little bit more the framework you are using.

NOTE: I listed only 10 of all the design problems I found, there are more than 50. I spent 3 months documenting all this issues, writing unit tests and UML diagrams.




Theme © iAndrew 2016 - Forum software by © MyBB