我尝试从我的视图中将参数传递给我的控制器函数,但我总是得到" Page Not Found"。 我一直在寻找可能来自here,here,and here的问题的解决方案,但我仍然无法找到可行的解决方案,而且我仍然没有找到解决方案。我知道可能是什么问题。我想我已经把一切都做好了,但它没有用。请告诉我是否有我做错的事。
这是我的控制器:Controll.php
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Controll extends CI_Controller{
public function about($thing){
$case = "About Us";
$data['page'] = $case;
$data['p'] = $thing;
print($thing);
//$this->load->view('/header/header',$data);
$this->load->view('about_us',$data);
$this->load->view('/footer/footer');
}
public function mountain_destination($thing){
$data['page'] = "Mountain Destination";
$data['p'] = $thing;
//$this->load->view('/header/header',$data);
$this->load->view('mountain_destination',$data);
$this->load->view('/footer/footer');
}
}
?>
这是我的路线设置:
$route['(:any)'] = "controll/$1";
$route['default_controller'] = "controll";
$route['404_override'] = '';
这是我在onClick调用的一个脚本,试图调用该控制器函数:
function goTab(thing,tab){
switch(thing){
case "about":
$body.load("<?php echo site_url('about'); ?>/"+$(tab).text().toLowerCase().replace(/ /g,''));
break;
case "mountain":
$body.load("<?php echo site_url('mountain_destination'); ?>/"+$(tab).text().toLowerCase().replace(/ /g,''));
break;
}
我的脚本运行良好,并生成正确的URL。例如,我把参数&#34; myteam&#34;进入&#34; goTab&#34;功能,它产生这样的链接: &#34; http://127.0.0.1/about/myteam&#34 ;.这个链接应该打电话给&#34;关于&#34;在我的控制器内部运行并通过&#34; myteam&#34;作为参数。但相反,它会返回&#34; Page Not Found&#34;。当我试着打电话给&#34;关于&#34;函数没有这样的参数:&#34; http://127.0.0.1/about&#34;,我错过了这样的参数错误:
Severity: Warning
Message: Missing argument 1 for Controll::about()
Filename: controllers/Controll.php
Line Number: 22
请帮帮我。 提前谢谢。
答案 0 :(得分:2)
您没有将其传递给SELECT e1.ref,subq.avg,SUM(volume)
FROM exchanges e1,
(SELECT e2.ref, AVG(value) as avg
FROM exchanges e2, valid_country vc
WHERE e2.country = vc.country
GROUP BY e2.ref) as subq
WHERE e1.ref = subq.ref
GROUP BY ref
方法。您正在寻找about
控制器中名为myteam
的方法。
修改你的路线;
Controll
希望这有帮助。
我的这个答案也可以帮到你;
答案 1 :(得分:0)
您可以创建一个变量并将其传递到constructor
中,只需在需要时使用
class Controll extends CI_Controller {
private $thing;
public function __construct() {
parent::__construct();
$this->thing = $this->uri->segment(3);
}
public function about() {
$data['p'] = $this->thing;
echo $this->thing;
}
public function mountain_destination($thing) {
$data['p'] = $this->thing;
echo $this->thing;
}
}