|
本帖最后由 abayomi.zou 于 2011-3-9 14:00 编辑
我想在view内调用model,写了下面的代码
PHP复制代码
$this->load->model("m_util","util");
$funcs = unserialize($this->session->userdata("func"));
foreach($funcs as $func){
printf("%s\n","<tr>");
printf("%s\n","<td>");
printf("%s\n",$func->name);
printf("%s\n","</td>");
printf("%s\n","<td>");
printf("%s\n",$func->url);
printf("%s\n","</td>");
printf("%s\n","<td>");
printf("%s\n",$this->util->showParentDir($funcs,$func->parent_id));-- 第 40行
printf("%s\n","</td>");
printf("%s\n","</tr>");
}
复制代码
出现错误
A PHP Error was encountered
Severity: Notice
Message: Undefined property: CI_Loader:util
Filename: views/v_func.php
Line Number: 40
Fatal error: Call to a member function showParentDir() on a non-object in D:\MyPhp\tzjy\application\views\v_func.php on line 40
这样子不行的吗?应该怎么做才行呢。。
我用的CI2.0。
m_util.php代码如下:
PHP复制代码
<?php
class M_util extends CI_Model {
function showParentDir ($funcs,$sel){
printf("%s\n","<select name='parent_id'>");
printf("%s\n","<option value='0'>顶级目录</option>");
foreach($funcs as $func){
if(isset($sel) && $sel==$func->func_id)
printf("%s\n","<option value='".$func->func_id."' selected>".$func->name."</option>");
else
printf("%s\n","<option value='".$func->func_id."'>".$func->name."</option>");
}
printf("%s\n","</select'>");
}
}
复制代码 |
|