[英]Call variable from view in Codeigniter
I am trying to call $data['form_value'] from view in Codeigniter, but that array returns empty. 我正在尝试从Codeigniter中的视图调用$ data ['form_value'] ,但是该数组返回空。
Here is my Controller: 这是我的控制器:
$data['field'] = $this->cc->get_form_names($data['selid']);
foreach($data['field'] as $key=>$valuee) {
$data['form_value'] = $this->cc->get_form_value($valuee->select);
}
Now in the View: 现在在视图中:
foreach($field as $key=>$valuee) {
echo "<span\"> ".$valuee->disp_name." :</span>";
<select name=\"\">";
foreach($form_value as $v=>$vv) {
$value = $vv->select;
echo "<option value=\"".$vv->select."\" >".$vv->select."</option>";
}
echo"</select> ";
}
When I do var_dump($form_value) it return array(0) { } 当我执行var_dump($ form_value)时,它返回array(0){}
How would I get that variable? 我将如何获得该变量?
You are overwriting form_value in loop. 您正在循环覆盖form_value。 Try below code in your controller.
在您的控制器中尝试以下代码。
$form_value = array();
foreach($data['field'] as $key=>$valuee) {
$form_value[] = $this->cc->get_form_value($valuee->select);
}
$data["form_value "] = $form_value ;
Modify your Controller
code like this, 像这样修改您的
Controller
代码,
$data['field'] = $this->cc->get_form_names($data['selid']);
foreach($data['field'] as $key=>$valuee) {
$data['form_value'][] = $this->cc->get_form_value($valuee->select);
}
$data['form_value']
should be an array to loop through it. $data['form_value']
应该是一个遍历它的数组。 You are using it as string and trying to loop through it. 您将其用作字符串并尝试遍历它。
Hope this helps :) 希望这可以帮助 :)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.