[resolved]Function in controller |
[eluser]isabelle[/eluser]
Hy everybody, On my way to learn code igniter and the mvc coding, i have my really first problem. I don't paste the model, but this one gets the datas of a website. In that datas there are the tags, the keywords in fact. (example: http://leweb2.be/Mandellia.html) These ones are separated by commas and i need to explode them via a function made for that. I tried to define it in the controller but when i call that function in the view, i have that error: Code: Fatal error: Call to undefined function explode_term() in C:\wamp\www\eclipse\annuaire\system\application\views\fiche_view.php on line 56 Is that the moment when i need to create my own libraries? Thanks in advance for your help, CONTROLLER Code: class Fiche extends Controller{ VIEW Code: <?php
[eluser]Yash[/eluser]
This is not right way to do this.I'm also new to this. What u should do is create function in view not in controller. Controller functions create global URL link ..like ur function will create yoursitepath/index.php/explode_term so use these functions more precisely. That what I thought.
[eluser]isabelle[/eluser]
But i don't think creating a function in the view is a nice way of working. I continue searching, thanks for your reply.
[eluser]Yash[/eluser]
Unless u use that function globally u can create function in view.Or use model approach for best results.
[eluser]isabelle[/eluser]
I wonder if should not user an helper... I'm trying to do that, i'll let u know.
[eluser]xwero[/eluser]
You can solve this 3 ways. - create a helper class with that function and autoload it. benefits : you can use the function without class reference - create a library with that function an autoload it benefits : you can use it anywhere in your code - add the function to your model and when you return the data you can do a first visual data manipulation using the function
[eluser]alexsancho[/eluser]
I prefer to use helpers for such things, you can load the helper on your controller and the function become available on your view. You has also the plugins, by definition a plugin is a single function an a helper a set of functions. Try this way and check the results. Regards
[eluser]isabelle[/eluser]
Excellent, big thank for your reply. I'm gonna make my first library so ![]()
[eluser]John_Betong[/eluser]
Hi Isabelle, Try this in your view: Code: function show_row($row) {
[eluser]isabelle[/eluser]
thanks, sure it works, but i prefer working with helpers or library, that's a better way of coding. Thanks anyway for your help. |
Welcome Guest, Not a member yet? Register Sign In |