2014-12-04 44 views
2

我試圖使用form_helper.php一個輔助類笨2.2.0 和下面是它給了錯誤,當我嘗試這樣做:笨2.2.0 form_helper給人錯誤

控制器文件

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

視圖文件

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

錯誤:

A PHP Error was encountered

Severity: Warning

Message: strpos() expects parameter 1 to be string, object given

Filename: helpers/form_helper.php

Line Number: 53

A PHP Error was encountered

Severity: 4096

Message: Object of class CI_Loader could not be converted to string

Filename: helpers/form_helper.php

Line Number: 61

Although it does print the tag.

What I could be doing wrong here ?

+2

form_open($ this,$ attributes)是我想的問題。第一個參數應該是您要鏈接到的控制器方法。 – Craig 2014-12-04 12:57:00

回答

2

您的代碼:

echo form_open($this, $attributes); 

是,正確的。它正確的:

echo form_open($YOUR_FORM_ACTION, $attributes); 

Reference

問題正在發生,因爲,你是路過$this,一個對象,而不是形式的行動(串)。

2

您不能使用$this作爲第一個參數,因爲它是內部CI對象。嘗試:

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