CI中load一个library的问题
本帖最后由 小白TO大白 于 2012-3-25 23:56 编辑$this->load->library('xxx');
$this->xxx->function()
为什么仍然报错要实例化一个对象呢,load不是可以直接用么?
另外补充下,library中的类的构造函数里有:
parent::__construct();
因为那个类已经继承了一个类。。
然后我写了个新的类,没有继承其他类的,按上面的方法又可以了。求指教
本帖最后由 sdink 于 2012-3-25 20:26 编辑
在load之前要实列化父类。 parent::__construct(); PHP里不知道咱叫,构造父类 貌似CI 的load会将类实例化,抽象类就不能这样加载了 $this->load->library('xxx');
$xxx->function()
试试 靠,我发现CI社区的人还是很热情的,感谢这么多热情之士。@Hex 呢 phptree 发表于 2012-3-25 22:40 static/image/common/back.gif
$this->load->library('xxx');
$xxx->function()
试试
试了,还是没用 sdink 发表于 2012-3-25 20:23 static/image/common/back.gif
在load之前要实列化父类。 parent::__construct(); PHP里不知道咱叫,构造父类
在controller里面写了,依然不行。但是load一个model之后,$this->xxmodel->function()可以 贴你的lib出来 sdink 发表于 2012-3-26 09:23 static/image/common/back.gif
贴你的lib出来
<?php
if (!defined('BASEPATH'))
exit('No direct script access allowed');
require_once('smarty/Smarty.class.php');
class My_Smarty extends Smarty
{
function __construct()
{
parent::__construct();
$tem_path = APPPATH.'views/';
$com_path = APPPATH.'cache/';
$this->template_dir = $tem_path; //模板目录
$this->compile_dir= $com_path; //编译目录
}
//加载指定模板并且同时加载默认加载模块
public function viewWithDefaultTemplate($model_path,$data_array = array())
{
//将数据传入到模板中去
foreach($data_array as $key => $value)
{
$this->assign($key,$value);
}
$this->display(HEADER_PATH); //加载头部模板
$this->display($model_path); //加载内容模板
$this->display(FOOTER_PATH); //加载尾部模板
}
}
?> $this->load->library('My_Smarty ');
print_r($this->My_Smarty )
看有没有你写的那些变量,template_dir,compile_dir等,按理说应该是没有问题的
页:
[1]
2