Welcome Guest, Not a member yet? Register   Sign In
validation of my understanding please
#1

[eluser]Marc Arbour[/eluser]
Dear CI community.

I need help validating what I am about to do before waisting time doing it if it's not correct.

I created a function called Get_Mandate_Name(id_mandate) that returns a string containing the name of the mandate, properly formatted like I want it. Now I need to use this everywhere in my code... In many many controllers.

I am about to create a helper called My_functions_helper.php to put in my application/helpers directory with all my functions like the one above...

Am I addressing my situation correctly or should I do otherwise?

Best regards.

Duke
#2

[eluser]n0xie[/eluser]
Maybe you should put it in MY_Controller so every controller has access to the function automatically?
#3

[eluser]Marc Arbour[/eluser]
[quote author="n0xie" date="1256762698"]Maybe you should put it in MY_Controller so every controller has access to the function automatically?[/quote]

Hello.

Would this mean I create a MY_Controller.php file into system/libraries instead of applications/helpers directory and all functions therein would automatically become available without me asking to load a helper?

If I understand you correctly... are you refering to this user_guide page or this user_guide?

Regards.

Duke

P.S.: English is not really my birth language. I may sound a little stupid but sometimes, classes, functions, libraries and helpers get a little confusing to me.
#4

[eluser]n0xie[/eluser]
[quote author="Marc Arbour" date="1256763291"]
Would this mean I create a MY_Controller.php file into system/libraries instead of applications/helpers directory and all functions therein would automatically become available without me asking to load a helper?
[/quote]
Yes exactly.

Quote:If I understand you correctly... are you refering to this user_guide page or this user_guide?
It's the first link. What you basically do is add functionality to the 'standard' controller which all your other controllers get 'free' access to, making your life a lot easier. You can read about it in this wiki article (thanks to jedd).
#5

[eluser]jedd[/eluser]
I reckon that if it's a function that just does formatting, that you'd put it in a helper, and autoload that helper. I typically have one helper per application - though I haven't written enough applications yet to know if this is going to scale - and copy-n-paste bits from other applications' helpers into same.

If it attempts to do a database lookup as part of the process (this isn't clear, but it's kind of implied by the fact the function takes an id and returns a string) I'd suggest you keep the DB side of things partitioned off into your model, and adopt the MY_Controller approach.

You say you'll use it 'almost everywhere' - and while I thing worrying about performance is often a waste of time, remember that MY_Controller is likely going to get loaded on all your controllers - even those that won't be using this function.
#6

[eluser]Marc Arbour[/eluser]
Hello.

I did manage to get this working by making a my_functions_helpers and autoloading it.

I also inserted
Code:
$ci = & get_instance();
$ci->load->database();
$query = $ci->db->query('select variables from table where condition');
To get access to databases in some functions.

Thanks guys for your help.

Duke




Theme © iAndrew 2016 - Forum software by © MyBB