自定义类库的问题
自定义类:<?php
if (!defined('BASEPATH'))
exit('No direct script access allowed');
class Useridentify {
var $p;
public function __construct($p ='') {
// Do something with $params
echo $p;
}
}
?>
控制器:
<?php
if (!defined('BASEPATH'))
exit('No direct script access allowed');
class Home extends CI_Controller {
public function index() {
$a = "hello";
$this->load->library('useridentify',$a);
}
}
为什么构造函数中不能输出参数p?
本帖最后由 bluelomo 于 2012-11-9 13:39 编辑
请见文档:http://codeigniter.org.cn/user_guide/general/creating_libraries.html
如下图所示,“当初始化类库时,你可以通过第二个参数动态的传递数组到类的构造函数中去”,换言之,如果你要传参数,你必须且只能使用一个动态数组格式,使用其他格式一律无效。
在自定义类库中 使用
public function __construct(){
parent::__construct();
$CI =& get_instance();
$CI->load->helper('url');
$CI->config->item('base_url');
}
报错 :Fatal error: Cannot access parent:: when current class scope has no parent in E:\APMServ5.2.6\www\htdocs\application\libraries\Sys_message.php on line 5
是怎么回事呢 楼上的,你确定你继承了一个父类? 楼主自定义类木有调用到吧
parent::__construct();
$CI =& get_instance();
$CI ->load->library('useridentify',$a);
这样试试!
传递变量并且要放了application/libraries下面
页:
[1]