0

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

Ben Fortune
  • 31,623
  • 10
  • 79
  • 80

2 Answers2

0

You need to add the parent to your __constructor function. Like this;

function __construct()
{
    parent::__construct();
}

This question should help you;

PHP Codeigniter - parent::__construct

Community
  • 1
  • 1
Craig
  • 1,823
  • 1
  • 11
  • 12
0

Use CI_Controller this

class Test extends CI_Controller {

I have just tested both on CI 2.x and on CI 3

application/controllers/Test.php

<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Test extends CI_Controller {

    function show_date() {

        $this->load->helper('date');
        echo "current date in mysql format " . date_mysql();

    }

}
?>

application/helpers/date_helper.php

<?php
function date_mysql( $time = false ){

    return date('Y-m-d H-i-s', !$time ? time() : $time);

}
?>

What is helpfull?

Adrian
  • 85
  • 6