Welcome Guest, Not a member yet? Register   Sign In
where to place fucntions that are used sitewide?
#1

[eluser]zoreli[/eluser]
Hi

I have some functions (like the one that build the navigation menu) which are used on whole site. At this time, I am writting those functions in every controller.

Consider the following peace of code:

Code:
// get school excursions for the top menu
            $this->load->model('excursionsModel');
     $this->db->where('catid = "6"');
            $data['schoolExcursions'] = $this->excursionsModel->get();

My front end template has: header, main_content and footer.

I need this code to build the main menu on the front end. And I have this code is in my header part. How can I write it once and call it only once?

Regards, Zoreli
#2

[eluser]johnpeace[/eluser]
looks like a helper to me. Read about helpers in the CI user guide.
#3

[eluser]InsiteFX[/eluser]
johnpeave is correct, take a look at ./system/helpers/url_helper.php it will show you how to create them etc;
#4

[eluser]zoreli[/eluser]
Thianks to both of you.

I will read the manual about helpers. Any other resources for reading?

Regaerds, Zoreli
#5

[eluser]InsiteFX[/eluser]
A good way to learn CI is to look at the source code in ./system/core ,/system/libraries and ./system/helpers

There are methods and stuff in there that is not listed in the Users Guide.




Theme © iAndrew 2016 - Forum software by © MyBB