Welcome Guest, Not a member yet? Register   Sign In
Sticking to CodeIgniter practices vs. making things easier for new developers to pick up
#1

[eluser]charlieD[/eluser]
Some of CodeIgniter's functionality is very useful; however sometimes I think the framework-specific ways of doing things would just make it harder for new developers (who perhaps aren't familiar with CodeIgniter) to pick up.

For example, there are a few 'helper' functions which just appear to be one line wrappers for a simple native PHP function, possibly with a tiny benefit.

In other situations, it's less clear whether using the framework would be beneficial or not.

For example, when adding a general function to deal with an array task, CodeIgniter's rules would say this would be added as a 'helper'. However, I personally would find it easier to follow if the function is wrapped in a 'Utils' class, e.g. $this->utils->doSomething(); rather than doSomething() makes it easier to follow and find the doSomething() method.

What is the best practice in situations like this? Is this a matter of personal preference or is it strongly recommended that you stick to the Framework at all times?
#2

[eluser]Michael Wales[/eluser]
I say whatever will help you develop your application and maintain it the best. Like Jolly said in this post:

Quote:My take:
function called from view = helper
function/method called from controller = helper, library, or model

A model is for getting/setting data, whether from a database, file, feed, etc - a fairly ignorant entity. A library class has methods that share and work with its variables. I think a library would normally have more functionality than a model - it could even use models. Maybe a library might make more sense in this case - especially for the payment gateway.
#3

[eluser]Rick Jolly[/eluser]
[quote author="charlieD" date="1188295538"]
For example, when adding a general function to deal with an array task, CodeIgniter's rules would say this would be added as a 'helper'. However, I personally would find it easier to follow if the function is wrapped in a 'Utils' class, e.g. $this->utils->doSomething(); rather than doSomething() makes it easier to follow and find the doSomething() method.
[/quote]

Since you probably don't need an instance of the Utils class you could call methods staticly: Utils::doSomething();. CI doesn't have any obvious way to create static classes. If you made a library CI would instantiate it. You could create a helper though, and instead of defining functions you could make it a class. That way CI wouldn't instantiate it and you could call methods statically: HelperClassName:ConfusedomeStaticMethod();.
#4

[eluser]charlieD[/eluser]
Static classes was something I thought was oddly missed out by CodeIgniter; this is a nice solution.




Theme © iAndrew 2016 - Forum software by © MyBB