![]() |
Call functions in to model.. - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: Call functions in to model.. (/showthread.php?tid=18327) Pages:
1
2
|
Call functions in to model.. - El Forum - 05-02-2009 [eluser]tnathos[/eluser] Hi, i have the next problem.. Y have a model whit several functions, i liked use code the one funcion in other function for reuse code in the same model and not rewrite the same code in varios funcionts..but i cant.. any know i can, CI permit load or call functions in the same model? if no how make this? example. Code: <?php Call functions in to model.. - El Forum - 05-03-2009 [eluser]Dam1an[/eluser] I'm not quite sure what you're after :S Do you want a common model which you can extend and then use those methods in all your models? Or a llibrray with common functionality which you can call from your models? :S Call functions in to model.. - El Forum - 05-03-2009 [eluser]Yorick Peterse[/eluser] [quote author="Dam1an" date="1241355388"]I'm not quite sure what you're after :S Do you want a common model which you can extend and then use those methods in all your models? Or a llibrray with common functionality which you can call from your models? :S[/quote] I think he wants to load a function that's stored into another function. Code: <?php Call functions in to model.. - El Forum - 05-03-2009 [eluser]tnathos[/eluser] i want use a function in the same model for other function... for reuse code and not rewrite the same code in severals funcionts.. for example, in this code.. i have 3 functions diferents but whit a same code for insert data in DB... this code its the same, but run in diferents event in my APP... its no call funcions bettewen a controller else into same model for reuse code. <?php MODEL.... FUNCTION A { insert into table a field a, b parametres -> post xxxxx delete * table b } FUNCTION B { insert into table a field a, b. parametres -> post xxxxx delete * table c } ?> I THINK WHAT CAN BE.... <?php MODEL FUNCTION A { CALL FUNCTION C delete * table b } FUNCTION B { CALL FUNCTION C delete * table a } FUNCTION C { insert into table a field a, b. parametres -> post xxxxx } ?> Call functions in to model.. - El Forum - 05-03-2009 [eluser]Dr. Seuss[/eluser] Yorick's post is almost your answer (I once had the same question). You use the "$this->functionname()" to call a function from a function that is defined WITHIN the same model / class. <?php MODEL FUNCTION A { $this->FUNCTION C delete * table b } FUNCTION B { $this->FUNCTION C delete * table a } FUNCTION C { insert into table a field a, b. parametres -> post xxxxx } ?> Call functions in to model.. - El Forum - 05-03-2009 [eluser]tnathos[/eluser] No works it... generate the next error.. Call to undefined method ClientModel::restTrans() in application\models\clientModel.php on line 118 code... Code: <?php Call functions in to model.. - El Forum - 05-03-2009 [eluser]Yorick Peterse[/eluser] [quote author="Dr. Seuss" date="1241388387"]Yorick's post is almost your answer (I once had the same question). You use the "$this->functionname()" to call a function from a function that is defined WITHIN the same model / class. <?php MODEL FUNCTION A { $this->FUNCTION C delete * table b } FUNCTION B { $this->FUNCTION C delete * table a } FUNCTION C { insert into table a field a, b. parametres -> post xxxxx } ?>[/quote] I still don't quite get what he wants, as far as I can read he now wants to use the same function for multiple tasks, if so you could do the following: Code: <?php Call functions in to model.. - El Forum - 05-03-2009 [eluser]tnathos[/eluser] No works it… generate the next error.. Call to undefined method ClientModel::restTrans() in application\models\clientModel.php on line 118 code example Code: <?php Call functions in to model.. - El Forum - 05-03-2009 [eluser]Yorick Peterse[/eluser] You forgot the () after $this->restTrans; It should be : Code: <?php Call functions in to model.. - El Forum - 05-03-2009 [eluser]tnathos[/eluser] same error.... Fatal error: Call to undefined method ClientModel::resta() in |