控制器/test.php
<?php
class Test extends Controller {
function __construct() {
}
function show_date(){
$this->load->helper('date');
echo "current date in mysql format" . date_mysql();
}
}
?>
申请/帮手
<?php
function date_mysql(){
if(!time){
$time = time();
}
return date('Y-m-d H-i-s', $time);
}
?>
而我的错误是:
致命错误:在第12行的F:\Xampp\htdocs\ci_series\application\controllers\test.php中调用非对象上的成员函数助手()
我能做什么??
发布于 2014-11-11 06:49:37
需要将父函数添加到__constructor函数中。就像这样;
function __construct()
{
parent::__construct();
}
这个问题应该对你有帮助;
发布于 2014-11-11 07:01:28
使用CI_Controller this
class Test extends CI_Controller {
我刚在CI 2.x和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);
}
?>
什么是有帮助的?
https://stackoverflow.com/questions/26867306
复制相似问题