passing parameters to a function in core MY_Controller - 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: passing parameters to a function in core MY_Controller (/showthread.php?tid=58423) |
passing parameters to a function in core MY_Controller - El Forum - 06-11-2013 [eluser]Unknown[/eluser] I hope that this is possible Can I pass parameters to functions in CORE/MY_Controller? I am developing a application that has three controllers and most of the functions are the same so I want to code functions ones and use them again in their respectable controllers when need. function like search_User_Name() will be in both of the controllers, it will be cool if i can get to code it once and reuse it. the problems that i am facing at the moment are The MY_Controller.php is not in the same folders as other controllers The search_User_Name() function has to receive parameters like search_User_Name($var1, $var2) I have a controller in the core folder as MY_Controller class MY_Controller extends CI_Controller{ public function __construct() { parent::__construct(); } public function Testing($var){ $function_var= $var; return $function_var; } } and i have a controller in the controller folder as Sub_Controlller class Sub_Controller extends MY_Controller{ public function __construct() { parent::__construct(); } public function Show(){ echo($this->Testing()); } } on the view i have echo anchor('Sub_Controller/Show/Parameter','Pass a parameter'); according to my understanding i was spouse to get the word "parameter" on the screen. can any help? passing parameters to a function in core MY_Controller - El Forum - 06-13-2013 [eluser]LuckyFella73[/eluser] Welcome to the forums! Did you try this: Code: public function Show($param){ Please use the CODE brakets when providing code in future posts! |