![](/img/trans.png)
[英]How to pass parameter from javascript to controller in codeigniter?
[英]How to pass url as parameter from view to controller using codeigniter
我在使用带有 codeigniter 参数的 function 时遇到问题。 I want to write a function which when we click the URL in view, automatically uses that URL address as parameter to connect to the function that I made in the controller.
我已经在使用
this->load->helper('url','form','array');
看法
<?php
foreach ($dataView as $items){
echo "<a href='".site_url("testcontroller/click/".$items['serviceURL']."")."'>".$items>['serviceURL']."</a>".'<br>';
?>
Controller
<?php
public function click($url=null){
var_dump($url);
$datauri['url']=$url;
}
?>
当我使用虚拟变量时,我看到已经通过的 URL 只是
< string(5) "http:">
但它应该是一个完整的 URL 例如
<http://sos.maracoos.org/stable/sos/hrecos/stationHRLCK8H-agg.ncml>
谁能帮我解决这个问题?
你可以使用这个:
public function click($url=null)
{
var_dump($this->uri->segment('3'));
$datauri['url']=$this->uri->segment('3');
}
要获得 url,您必须将整个 URL 作为参数传递。 在 controller 中,您可以接收 url 作为参数。 在这里,您没有将 url 作为参数传递。
首先尝试使用urlencode()
对 URL 进行编码,如下所示:
foreach ($dataView as $items){
echo "<a href='".site_url("testcontroller/click/".urlencode($items['serviceURL'])."")."'>".$items>['serviceURL']."</a>".'<br>';
}
我认为http:
之后的/
被解释为不同的 URL 段
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.