普通网友 2013-12-06 13:12
浏览 50
已采纳

在codeigniter中的Helper类中动态填充下拉列表

I'm using codeigniter and trying to write a Helper class for loading dropdown dynamicly according to model name and the attribute which is the Column name for view.

function dropdown($Class,$Attribute)
{
$Output=NULL;
define("CLASSNAME", $Class."_model");
define("ATTRIBUTE", $Attribute);
$CI = get_Instance();
$CI->load->model(CLASSNAME);
$FullData=$CI->CLASSNAME->get();
foreach ($FullData as $Data) 
{
    $Output.='<option value="'.$Data->Id.'">'.$Data->ATTRIBUTE.'</option>';
}
return $Output;
}

But when I call it means i am getting this error:

A PHP Error was encountered
Severity: Notice
Message: Undefined property: News::$CLASSNAME
Filename: helpers/component_helper.php
Line Number: 11
Fatal error: Call to a member function get() on a non-object in C:\xampp\test\application\helpers\component_helper.php on line 11
  • 写回答

1条回答 默认 最新

  • dongwan0574 2013-12-06 13:38
    关注

    it seems that you may have missed a syntax

    $CI = get_Instance();
    

    use $CI =& get_Instance(); instead and check again if the issue is resolved.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?