Codeigniter helper extending |
controller/test.php
<?php class Test extends Controller { function __construct() { } function show_date(){ $this->load->helper('date'); echo "current date in mysql format" . date_mysql(); } } ?> application/helpers <?php function date_mysql(){ if(!time){ $time = time(); } return date('Y-m-d H-i-s', $time); } ?> and im gettting error: Fatal error: Call to a member function helper() on a non-object in F:\Xampp\htdocs\ci_series\application\controllers\test.php on line 12 what can i do??
You did not say what version of CodeIgniter you are running, but the helper your loading is using
CodeIgniter 3.x.x helper loading. For CodeIgniter 4 you load helps like below. PHP Code: helper('date'); What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
I believe this is a limitatiom in CIs dispatcher. What you want is a seperate folder foe additional controllers and I am not sure if CI 3 makes that possible. It should be possible fpr you to extend the CI dispatcher (assuming its a class, not sure about that) and add this functionality. It would not be a trivial thing. you would be essentially monkey pat hing CI making down the road updates much harder.
Your problem with a nothet dispatching strategy comes down to defining the actions and mapping uri to class:methods. CI does this automagically for you. So you are stuck with having an automagical dipatcher or one too general that it requires an additio al config file. It's a tough problem but can be solved with either strategy.
Just a NOTE:
You should not use F: as a drive in Windows, F: is reserved for Windows Networking! Also if you read the XAMPP docs they recommend using XAMPP on drive C:. What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
|
Welcome Guest, Not a member yet? Register Sign In |