Mike Rifgin
Mike Rifgin

Reputation: 10745

Common functions in code igniter

I have some common functions that I've written that I'm currently copying in to each of my controllers. An example is a method that puts together my main navigation - I'm currently copying it in to each and every one or my controllers.

Is there any way I can put these common functions somewhere so I don't have to repeat the same code in each controller?

I thought creating core classes in the user guide would be it but that only seems to be to extend the current core

Upvotes: 1

Views: 1901

Answers (1)

raidenace
raidenace

Reputation: 12826

There is a whole bunch of ways to do this:

  1. Like Rikesh said, use Helpers.
  2. If you have a whole bunch of such functions, structure them into Libraries

Usually in CI, helpers are just files with a bunch of "helper" functions. Libraries are better organized into classes. Personally, I would create a custom lib called Common or maybe specialize them further like a Nav Lib or so. Thats why I love CI its so simple yet flexible!

Upvotes: 2

Related Questions