![]() |
Functions can't be called from libraries. - 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: Functions can't be called from libraries. (/showthread.php?tid=58018) |
Functions can't be called from libraries. - El Forum - 05-06-2013 [eluser]behnampmdg3[/eluser] Hello; In the example below I want to keep my controller small so I keep all my validations in another place. Well I think a good way would be to keep them in libraries/my_functions. But for some reason I cannot call any functions from libraries/my_functions. In the example I can easily call validate_search() from my controller but I cannot call any functions from there (from my_functions)! For example the callback function callback_valid_product_class below doesnt work, or test() does not work either. 2 questions: 1 - Why cant I call these functions? 2 - Is this the proper way of keeping controller light? Thank you Controller: Code: if ( ! defined('BASEPATH')) exit('No direct script access allowed'); Code: if ( ! defined('BASEPATH')) exit('No direct script access allowed'); Functions can't be called from libraries. - El Forum - 05-07-2013 [eluser]jairoh_[/eluser] 1. have you called the library? 2. try putting $CI =& get_instance(); into a constructor 3. are there errors? Functions can't be called from libraries. - El Forum - 05-07-2013 [eluser]TheFuzzy0ne[/eluser] By default, CodeIgniter checks in 2 places for callbacks -- Your controller, and the validation class itself. If you have your callbacks anywhere else, you will either need to modify the form validation class, or you will need to add an alias method to either the form validation class or your controller. I think the best option is to have a separate version of the form validation class for each "section" of your Web site. For example, one for user validation, one for product validation and so on. Then you can simply load the class you need, and all of the relevant methods are there. ./application/libraries/Product_validation.php Code: <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); So from your controller: Code: $this->load->library('product_validation'); Hope this helps. Functions can't be called from libraries. - El Forum - 05-07-2013 [eluser]behnampmdg3[/eluser] Thanks TheFuzzy0ne. |