ビュー内にこのコードがあります。
$country = array(
'id' => 'country',
'name' => 'country',
'value' => get_user_info('country'),
'size' => 30
);
<tr>
<td><?php echo form_label('Country', $country['id']); ?></td>
<td><?php echo form_input($country); ?></td>
<td style="color: red;"><?php echo form_error($country['name']); ?><?php echo isset($errors[$country['name']])?$errors[$country['name']]:''; ?></td>
</tr>
get_user_info() は、私の form_helper で次のように定義された関数です:
Form_Helper.php
if(! function_exists('get_user_info')){
function get_user_info($field)
{
$ci = & get_instance();
$ci->load->model('users');
return $ci->users->get_user_profile($field);
}
}
ご覧のとおり、この関数内でユーザー モデルを介してデータベースにアクセスします。ユーザー_モデル
function get_user_profile($field)
{
$user_id = $this->session->userdata('user_id');
$this->db->select($field);
$this->db->where('user_id',$user_id);
$query = $this->db->get($this->profile_table_name);
if($query->num_rows()==1)return $query->row();
return NULL;
}
アイデアは、ページの読み込み中にフォームの国フィールドを自動入力することです。
しかし、ビューでは、このエラーが発生しています
A PHP Error was encountered
Severity: Warning
Message: htmlspecialchars() expects parameter 1 to be string, object given
Filename: helpers/form_helper.php
Line Number: 646
何が問題になる可能性がありますか?
誰かが何が起こっているのか知っていますか? または、過去に誰かがそのようなことをしたことがありますか?
ヘルパー関数内でモデルにアクセスするのは正しい方法ですか?
ありがとう
編集
より良く、より速く行うには、コントローラーからモデルを呼び出してから、さまざまな値をビューに渡します。
コントローラ
$d = $this->users->get_user_profile('country, telephone, city, street, address, town');
$d2 = Array(
'telephone' => $d->telephone,
'country' => $d->country,
'city' => $d->city,
'street' => $d->street,
'address' =>$d->address,
'town' => $d->town);
$this->template->write_view('contentw','dashboard/profile', $d2);
$this->template->render();
そこで、ヘルパー ファイルに追加した関数を削除します。
この方法は私のために働いています。
回答ありがとうございました