php - Hit Counter en Codeigniter
html web (1)
Lo hice funcionar bien cuando cargué el ayudante $this->load->helper(''counter'');
aplicación> core> 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();
}
}
Tengo el código debajo de esto:
(Paso a paso)
- Pon el
counter.txt
enAPPPATH . ''logs/counter.txt''
APPPATH . ''logs/counter.txt''
- Hacer
counter_helper.php
establecido enAPPPATH . ''helpers/counter_helper.php''
APPPATH . ''helpers/counter_helper.php''
; - Autoload ayudante recién creado en
APPPATH . ''config/autoload.php''
archivoAPPPATH . ''config/autoload.php''
; - Haga
MY_Controller.php
enAPPPATH . ''core/MY_Controller.php''
APPPATH . ''core/MY_Controller.php''
- Cualquier controlador debe extender
MY_Controller
lugar deCI_Controller
; -
<?php echo $this->count_visitor;?>
eco en la página con:<?php echo $this->count_visitor;?>
El Ayudante:
<?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];
}
}
El núcleo :
<?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 */
El controlador :
<?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);
}
}
La vista :
<?php echo $this->count_visitor;?>