CodeIgniter Forums
Codeigniter helper extending - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: Libraries & Helpers (https://forum.codeigniter.com/forumdisplay.php?fid=11)
+--- Thread: Codeigniter helper extending (/showthread.php?tid=86011)



Codeigniter helper extending - RajeevElzrando - 01-01-2023

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??


RE: Codeigniter helper extending - InsiteFX - 01-02-2023

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'); 



RE: Codeigniter helper extending - AkinBredailns - 01-31-2023

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.


RE: Codeigniter helper extending - InsiteFX - 03-22-2023

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:.