简体   繁体   English

在代码点火器中将值从View传递到Controller

[英]Passing value from View to Controller in code igniter

I am trying to pass a value from View to Controller in Code Igniter and it is a part of a link the value i need to pass is "Backup/Aircrack" 我试图将值从View传递到Code Igniter中的Controller,它是链接的一部分,我需要传递的值为“ Backup / Aircrack”

How ever on the controller side all i am receiving is Backup not the rest ?? 在控制器方面,我所收到的全部是备份,而不是其余?

Any suggestions?? 有什么建议么??

this is one of the alernative way to get value if ur confused with codeigniter segment function 如果您将其与codeigniter段函数混淆,这是获取价值的一种替代方法

<a href="/controller/function?value1=answer1&value2=answer2">Click me</a>

controller: 控制器:

fucntion function_name(){
if($this->input->get())
{
$value1 = $this->input->get('value1');
$value2 = $this->input->get('value2');
}
}

Assuming your link is something like; 假设您的链接类似于:

<a href="/foocontroller/barmethod/Backup/Aircrack">Click me</a>

Then your controller should be something like; 然后,您的控制器应该类似于:

public function barmethod($param1, $param2)
{
    // $param1 would be Backup
    // $param2, would be Aircrack
}

NB This is assuming you haven't done anything funcky with your routing. 注意:这是假设您对路由没有做任何有趣的事情。

try the below option too.. 也尝试以下选项。

in your controller, include / load the url helper as below 在您的控制器中,如下所示包含/加载网址帮助器

$this->load->helper('url');

and try this below code. 并尝试下面的代码。 The position count starts from "1". 位置计数从“ 1”开始。 So the 1st segment is "foocontroller". 因此,第一段是“ foocontroller”。

echo $this->uri->segment(3) // this will return the Backup
echo $this->uri->segment(4) // this will return the Aircrack

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM