【问题标题】:CodeIgniter 2.2.0 form_helper giving errorsCodeIgniter 2.2.0 form_helper 给出错误
【发布时间】:2015-02-02 08:48:18
【问题描述】:

我正在尝试使用 form_helper.php 一个辅助类 codeigniter 2.2.0 以下是我尝试这样做时给出的错误:

控制器文件

 $this->load->helper('form');

查看文件

<?php 
  $attributes = array('class' => 'form-horizontal', 'id' => 'admin-form');
  echo form_open($this, $attributes);
?>

错误:

遇到 PHP 错误

严重性:警告

消息:strpos() 需要参数 1 是字符串,给定对象

文件名:helpers/form_helper.php

行号:53

遇到 PHP 错误

严重性:4096

消息:CI_Loader 类的对象无法 转换为字符串

文件名:helpers/form_helper.php

行号:61

虽然它确实打印了标签。

我在这里做错了什么?

【问题讨论】:

  • form_open($this, $attributes) 我认为是你的问题。第一个参数应该是你要链接的控制器方法。

标签: php html css codeigniter


【解决方案1】:

您不能使用$this 作为第一个参数,因为它是一个内部 CI 对象。试试:

echo form_open('controller/method', $attributes);

【讨论】:

    【解决方案2】:

    您的代码:

    echo form_open($this, $attributes);
    

    不正确。更正为:

    echo form_open($YOUR_FORM_ACTION, $attributes);
    

    Reference

    出现问题的原因是,您传递的是 $this,这是一个对象而不是表单操作(字符串)。

    【讨论】:

      猜你喜欢
      • 2014-07-30
      • 1970-01-01
      • 2014-12-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-06-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多