我有下面的代码:
(一步步)
- Put
counter.txt
in APPPATH . 'logs/counter.txt'
- Make
counter_helper.php
set in APPPATH . 'helpers/counter_helper.php'
;
- 自动加载新创建的助手
APPPATH . 'config/autoload.php'
file;
- Make
MY_Controller.php
in APPPATH . 'core/MY_Controller.php'
- 任何控制器都应该扩展
MY_Controller
代替CI_Controller
;
- 在页面上回显它:
<?php echo $this->count_visitor;?>
帮手:
<?php defined('BASEPATH') OR exit('No direct script access allowed.');
if ( ! function_exists('count_visitor')) {
function count_visitor()
{
$filecounter=(APPPATH . 'logs/counter.txt');
$kunjungan=file($filecounter);
$kunjungan[0]++;
$file=fopen($filecounter, 'w');
fputs($file, $kunjungan[0]);
fclose($file);
return $kunjungan[0];
}
}
核心 :
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class MY_Controller extends CI_Controller
{
public $count_visitor;
public function __construct()
{
parent::__construct();
$this->count_visitor = count_visitor();
}
}
/* End of file MY_Controller.php */
/* Location: ./application/core/MY_Controller.php */
控制器:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Home extends MY_Controller {
public function index() {
$data=array('isi' =>'home/index_home');
$this->load->view('layout/wrapper',$data);
}
}
风景 :
<?php echo $this->count_visitor;?>
The code return an error like below :
当我加载助手时我让它工作正常$this->load->helper('counter');
应用程序 > 核心 > MY_Controller.php
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class MY_Controller extends CI_Controller
{
public $count_visitor;
public function __construct()
{
parent::__construct();
$this->load->helper('counter');
$this->count_visitor = count_visitor();
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)