普通网友 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.

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

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?