我是CodeIgniter的新手,刚刚发现使用GET方法通过URL传递变量的困难(例如domain.com/page.php?var1=1&var2=2).
我认为一种方法是传递URI段中的变量,但还没有弄清楚如何做到这一点,因为它似乎创建了在控制器中具有一个名为特定URI段的函数的期望?
无论如何我没有使用GET,而是决定通过使用隐藏输入字段中的变量调整提交按钮(伪装成链接)来使用POST.我已经创建了以下解决方案似乎工作正常,但我想知道我是否在这里正确的轨道或是否有更简单的方法通过CodeIgniter中的链接传递变量?
我在application/libraries /中创建了以下类
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class C_variables {
function variables_via_link($action, $link_text, $style, $link_data) {
$attributes = array('style' => 'margin:0; padding:0; display: inline;');
echo form_open($action, $attributes);
$attributes = array('class' => $style, 'name' => 'link');
echo form_submit($attributes, $link_text);
foreach ($link_data as $key => $value){
echo form_hidden($key, $value);
}
echo form_close();
}
}
?>
Run Code Online (Sandbox Code Playgroud)
使用以下CSS:
/*
SUBMIT BUTTON AS LINK
adapted from thread: http://forums.digitalpoint.com/showthread.php?t=403667
Cross browser support (apparently).
*/
.submit_as_link {
background: transparent; …
Run Code Online (Sandbox Code Playgroud)