trying to load multiple functions within a function.... |
[eluser]stevenazari[/eluser]
Hi guys, I know I've probably read the usermanual wrong but I have tried and searched the forums for help... is there anyway I can load a function within another function or just call to it once the first function is completed? I want to upload an mp3 and at the end of it do some repetative code (that is used throughout the site to get data) I want the repetative code put into a function and then call the function when I want it... I checked out here about loaders and didnt have any luck with that... and I tried here (the functions page) and it said something about _remap() possibly being useful... can someone give some advice? the repetative function I have is called "function show()" so in the function I wanted to put it in I put in Code: function upload($show) but that didn't do anything.... the page should have redirected back to the upload page but it just stopped like it didn't load the function. Any advice?
[eluser]Ben Edmunds[/eluser]
Hey, If it is a repetitive task that works with data then you might want to put it in a model. Then you can just load it with Code: $this->load->model('data_model'); and use it like Code: $this->data_model->do_something(); Also you have a problem with your syntax. When calling a function/method the syntax isn't: Code: function upload($show) it is: Code: function upload($show) unless you are passing the name of the method you would like to call as $show, which probably isn't a good idea...
[eluser]stevenazari[/eluser]
[quote author="Ben Edmunds" date="1255469309"] Also you have a problem with your syntax. When calling a function/method the syntax isn't: Code: function upload($show) it is: Code: function upload($show) unless you are passing the name of the method you would like to call as $show, which probably isn't a good idea...[/quote] hehe I thought as much but on the userguide page it has: Code: function _remap($method) thought that might be wrong. ok so I should put it in the model... gonna give it a whirl ![]()
[eluser]BrianDHall[/eluser]
$this->$method() is the use of a variable function call - if you pass the remap function, say, "sha1" PHP would parse it as $this->sha1().
[eluser]stevenazari[/eluser]
ahh ok, well I used $this->show(); and it worked ![]()
[eluser]jedd[/eluser]
If the function is required in one controller only, keep it in the controller and stick an _ at the start of its name (unless you actually want it to be publicly visible).
[eluser]stevenazari[/eluser]
ok ![]()
[eluser]Colin Williams[/eluser]
Quote:If it is a repetitive task that works with data then you might want to put it in a model If it is a task at all, it should be in a model.
[eluser]stevenazari[/eluser]
oh... I've been putting them in the controller lols. well I'll just move it into the model and call it. This is great now I can use the whole mvc lol... I just need to learn more and I'll be on my way ![]() |
Welcome Guest, Not a member yet? Register Sign In |