【问题标题】:How can I pass arguments from view to controller?如何将参数从视图传递到控制器?
【发布时间】:2018-07-10 04:03:12
【问题描述】:
如何将参数从视图传递到控制器?
大家好!我在项目中工作,但我有一个问题。
我想将一个参数从我的视图传递给我的控制器,然后使用这个变量来获取我的数据库的结果。
我的看法:
<? $gCC = $this->getCustomer($gQ['id_u']);
foreach($gCC as $gC): ?>
Nombre<br />
Empresa<br />
<i class="fa fa-envelope" aria-hidden="true"></i> direccion@direccion.com
<? endforeach; ?>
我的控制器
$data['getCustomer'] = $this->generals->getCustomer($id);
感谢您的帮助
【问题讨论】:
标签:
php
codeigniter
arguments
【解决方案1】:
您可以使用anchor 标签在您的视图中传递single 或multiple 参数。
<a href="http://example.com?test=1">dummy_name</a>
您可以通过控制器中的GET 方法获取test 参数的值。
$this->input->get('test'); //gives you 1 in your controller
您也可以在视图中按段传递参数。
<a href="http://example.com/test_1/test_2/test_3/test_4">dummy_name</a>
您可以通过控制器中的URI 段获得价值。
$this->uri->segment(1); //gives you test_1 in your controller
$this->uri->segment(2); //gives you test_2 in your controller
$this->uri->segment(3); //gives you test_3 in your controller
$this->uri->segment(4); //gives you test_4 in your controller