CodeIgniter Forums
Advantages/Disadvantages of using helpers - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Advantages/Disadvantages of using helpers (/showthread.php?tid=39436)



Advantages/Disadvantages of using helpers - El Forum - 03-10-2011

[eluser]Unknown[/eluser]
What are the advantages/disadvantages of using helpers(specifically for views)? Ive been using CI for about 1.5 years and see myself using standard HTML vs using the CI helpers. Is there any large benefit to using CI helpers (such as security) or are they just there if you choose to use them? Also when it comes to my model I end up using a lot more of $this->db->query("query") vs the built in DB helpers. Once again are there added benefits to using the DB helpers or is query just as efficient?


Advantages/Disadvantages of using helpers - El Forum - 03-10-2011

[eluser]bretticus[/eluser]
Helpers:

These are shortcuts. Nothing more. I see two advantages when you factor in views:

1. If you have dynamically generated markup, a function may help to keep code out of your view (and it's portable.)
2. Using the form helper, for example, offers an easy way to maintain the state of your form inputs over posts. Sure you can write this yourself, but why do it every time when it's conveniently packaged in the helper for you to use?

Active Record:

If you ever anticipate using a different RDBMS for your application someday, AR is a database abstraction, and (at least in theory) you can use that other RDBMS without changing any code if you've used AR in every instance. AR also offers many shortcuts.

PDO is also a database abstraction class that you could use. Same concept (except for the shortcut aspect I suppose.)

Cheers


Advantages/Disadvantages of using helpers - El Forum - 03-11-2011

[eluser]Vheissu[/eluser]
Helpers are the equivalent of including a PHP script of functions in your application that can be used anywhere. That's what a helper is. Any example is Wordpress, Wordpress I guess you could say is comprised mostly of standalone functions that are included.

Helpers are good for things like functions that create menu's etc and you can use them to access other parts like the database class, session class, etc.