我正在尝试在 CodeIgniter 视图中的文本框中显示数组格式的值$raw
这是我在控制器中使用的功能:
public function pricing($raw='array')
{
if ($raw === 'array')
{
return $this->result_array();
}
}
我试过这个,但仍然message:array to string conversion
我在视图中使用$raw
"add_calendar.php":
<?php echo(['name'=>'tohr','class'=>'form-control','placeholder'=>'Enter total hire rate','value'=>'$raw'])?>
您不能回显数组,因为 echo 需要字符串作为其参数。由于您尝试将值回显到文本框,因此可能需要执行此操作。
加载视图时,$raw
传递到视图。
$data = array('raw'=>$raw);
$this->load->view('add_calendar', $data);
然后在视图中使用form_input
创建一个文本框。
echo form_input(['name'=>'tohr','class'=>'form-control','placeholder'=>'Enter total hire rate','value'=>$raw]);
将数组从控制器传递到查看
$raw
是一个变量,不要使用单引号'
$data['record'] = array('name'=>'tohr','class'=>'form-control','placeholder'=>'Enter total hire rate','value'=> $raw);
return $this->load->view('file', $data);
视图
您可以将这些值与或不带有 HTML 标记一起使用
没有 HTML 标记
<?= $name ?> //tohar
<?= $class ?> //form-control
<?= $raw ?>
使用网页标签
<td><?= $name ?></td>
<p><?= $name ?></p>
<h3><?= $name ?></h3>