一个简单问题,控制器里面,如何申明一个变量,让每个...
<?php
class Blog extends CI_Controller {
function __construct()
{
parent::__construct();
}
$str = '申明'
public function index()
{
echo $str.'1';
}
public function sec()
{
echo $str.'2';
}
}
?>
最简单的PHP你都没有看, var $str='';调用时$this->$str
http://www.php.net/manual/zh/keyword.class.php
类是变量与作用于这些变量的函数的集合。变量通过var来定义,函数通过 function 来定义,
<?php
class His_data extends MY_Controller {
var $table = '2012ppt;
function __construct()
{
parent::__construct();
}
function index()
{
echo $this->$table;
}
}
?>
结果:
A PHP Error was encounteredSeverity: NoticeMessage: Undefined variable: tableFilename: controllers/his_data.phpLine Number: 15
要写$this->table;
页:
[1]