简体   繁体   English

如何避免在URL中传递参数

[英]How to avoid passing argument in URL

Hi professionals have a good day. 嗨专业人士有一个美好的一天

I am new to this Codeigniter framework. 我是这个Codeigniter框架的新手。

Question 1: how to avoid passing argument in url or is there any other option like using dummy value or default value instead of passing original value? 问题1:如何避免在url中传递参数或者是否有其他选项,比如使用虚拟值或默认值而不是传递原始值?

Example : Currently i have like this 示例:目前我喜欢这个

http://localhost/manage?keyword1=SAP&keyword2=LAB

but i want it to be like this 但我希望它像这样

http://localhost/manage?keyword1=XXX&keyword2=YYY

Question 2: i have seen some example, in that they are using remap function to accomplish this task but i didnt get how remap work . 问题2:我已经看到一些例子,因为他们使用重映射功能来完成这个任务,但我没有得到重映射的工作方式。 is this right way do to? 这是正确的方法吗?

please give your suggestion and tell me the right way and sorry it may be a silly question but i searched lot i didnt anything . 请给出你的建议,并告诉我正确的方式,对不起,这可能是一个愚蠢的问题,但我搜索了很多我没有做任何事情。 thanks in advance 提前致谢

in Codeignitor you have to pass like this http://localhost/manage/controller/method/xxx/yyy 在Codeignitor中你必须像这样传递http://localhost/manage/controller/method/xxx/yyy

then in controller 然后在控制器中

function method ( $x , $y )
{
  echo $x;
  echo $y;
}
function somefunction ($param1 = null, $param2 = null)
{



}

if the params are not passed, then it will have the default values null , but if the arguments are passed then you could handle them like this: 如果params没有被传递,那么它将具有默认值null ,但是如果传递了参数,那么你可以像这样处理它们:

function somefunction ($param1 = null, $param2 = null)
{
   $param1 = intval($param1) //if you want it to be int
   $param2 = floatval($param2) //if you want it to be float


}

if you want to change the parameters visually in the browser, then just redirect it like this: 如果你想在浏览器中直观地更改参数,那么只需重定向它:

function somefunction ($param1 = null, $param2 = null)
{
   if($param1 == null || $param2 == null)
  {
      $param1 = 'XXX'; //put any value you want by your logic
      $param2 = 'YYY'; //put any value you want by your logic
      header("Location: http://localhost/manager/somefunction/".$param1.'/'.$param2);
  }


}

In codeigniter, there is a library called 'session'. 在codeigniter中,有一个名为“session”的库。 In this library there is a functionality called flashdata. 在这个库中有一个名为flashdata的功能。 This acts just like a $_POST method, however it does not require a form. 这就像一个$ _POST方法,但它不需要表单。

Example: To set a variable in flashdata: 示例:要在flashdata中设置变量:

$this->session->set_flashdata('example', $variable1);

'example' is the name of your flashdata and $variable is what it's storing. 'example'是flashdata的名称,$ variable是它存储的名称。

To access your data on the next page: 要在下一页访问您的数据:

$variable2 = $this->session->flashdata('example');

$variable2 will then equal whatever you set $variable1 as in the previous page. $ variable2将等于你在上一页中设置的$ variable1。

Hope this helps! 希望这可以帮助! Just an alternative to passing an argument through the URL. 只是通过URL传递参数的替代方法。

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

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