如何将php变量从视图(html)发送到控制器
这是我的html代码。我想将“如何将php变量从视图(html)发送到控制器,php,html,codeigniter,codeigniter-2,Php,Html,Codeigniter,Codeigniter 2,这是我的html代码。我想将“$category\u edit->c\u name”值传递给我的Update()控制器。我正在从另一个控制器获取“$category\u edit”变量 我正在使用CodeIgniter框架 <form method="post" action="<?php echo base_url('admin/category/update');?>"> <label>Parent Category: </label><
$category\u edit->c\u name
”值传递给我的Update()
控制器。我正在从另一个控制器获取“$category\u edit
”变量
我正在使用CodeIgniter框架
<form method="post" action="<?php echo base_url('admin/category/update');?>">
<label>Parent Category: </label></br>
<select name="parent_id">
<?php
echo '<option value="' .$category_edit->id .'">';
echo $category_edit->p_name;
echo '</option>';
?>
</select>
<label>Category</label>
<input type="text" name="<?php echo $category_edit->c_name; ?>" id="category_name" value="<?php echo $category_edit->c_name; ?>">
<button>Update</button>
</form>
在HTML中进行一些更改(参见下面的代码)
请检查此参考代码:
public function update_view()
{
$this->load->model('category_model');
$data['category_edit'] = $this->category_model->get_category_values(); // return array
$data['extra_variable'] = 'lorem ipsum';
$this->load->view('category/update_view', $data);
}
在您的类别/update_view.php
:
<form method="post" action="<?php echo base_url('admin/category/update');?>">
<label>Parent Category: </label></br>
<select name="parent_id">
<?php
echo '<option value="' .$category_edit['id'] .'">';
echo $category_edit['p_name'];
echo '</option>';
?>
</select>
<label>Category</label>
<input type="text" name="<?php echo $category_edit['c_name']; ?>" id="category_name" value="<?php echo $category_edit['c_name']; ?>">
<button>Update</button>
</form>
类别
您需要添加静态字段的名称,而不是任何变量。
所以试着像这样添加
<input type="text" name="category_name" id="category_name" value="<?php echo $category_edit->c_name; ?>">
$category\u edit这不是GLOBAL变量。请检查我的答案和控制器代码。错误为未定义变量:类别\u编辑。这意味着category\u edit
数组为空。错误为未定义变量:category\u edit
。这意味着category\u edit
数组为空。你的答案是错的。它不会打印任何要查看的数据。dude,这是您的工作,因为它不能在您执行数据库工作时返回空数组。或“对其进行验证”。“我可以告诉你路径,而不是完整的程序”。我完全正确,这是我项目的同一份副本。在你看来。请参阅打印内容。错误为未定义变量:category\u edit
。这意味着category\u edit
数组为空。你的答案是错的。它不会打印任何要查看的数据。此数据用于控制器,对于视图,您必须获取它。用户已从视图向控制器发出请求
<form method="post" action="<?php echo base_url('admin/category/update');?>">
<label>Parent Category: </label></br>
<select name="parent_id">
<?php
echo '<option value="' .$category_edit['id'] .'">';
echo $category_edit['p_name'];
echo '</option>';
?>
</select>
<label>Category</label>
<input type="text" name="<?php echo $category_edit['c_name']; ?>" id="category_name" value="<?php echo $category_edit['c_name']; ?>">
<button>Update</button>
</form>
<input type="text" name="category_name" id="category_name" value="<?php echo $category_edit->c_name; ?>">
$this->input->post('category_name');