0

In a codeigniter project i have to do some set of stuff in one than one controller.
I code all that stuff in a function and now i need to call whenever necessary.
i think Writing this function in more than one controller is not good.
i have 2 options,

  1. create a helper and write these function in that and include the helper in necessary controllers.
  2. Since i have extended CI base controller (My_Controller) and most of my controllers are extended that controller, i can write this function to my base controller also.

I have confused which one is better, right way?
Which one will speed up the process?
Is the second way slows the site?

Vibin TV
  • 822
  • 9
  • 28
  • This is pretty much the reason the ability to extend the core classes exists. I'm not sure where the confusion is, especially if you already have the MY_Controller written. – Rick Calder Feb 25 '13 at 12:48
  • Yes. Reading others answers and comparing my code i think MY_controller is the best option as it does not need any inclusion in my current code. If i put the needed stuff in library or helper i need to load them in my other controllers. i think by considering performance and speed MY_controller is better. – Vibin TV Feb 26 '13 at 07:02

2 Answers2

1

They are identical for all intents and purposes.

Using a helper allows you to make the code portable, so you can use it in other projects, or to be called from anywhere in the code base, in the case of a formatting function for example

If you were planning to put it in a controller, then MY_Controller is best bet

jmadsen
  • 3,635
  • 2
  • 33
  • 49
1

Just to help you on you endeavor what i do is: (this is just me)

  1. If i need to use something in the views, i use a helper a custom one or built in.

  2. If i want to do something on a controller that other controller will be using too and don't want it to mess up or crowd my controller i use a library (pretty much you can use a helper but i chose to use a library)

  3. If i want to load lets say a method, to affect Globally or some of the controller i use the base controller. (you could also use helper or library)

The key is you are not restricted to one, choose the best that suits you, as the saying goes, there are many ways to skin a cat, but please don't skin a cat..

tomexsans
  • 4,454
  • 4
  • 33
  • 49