我尝试了以下使用路由和控制器的方法,并尝试从controller方法获取参数值,但得到的结果为$ 1。但实际上,我通过了3。
routes.php
$route['helloword/:any'] = "FirstProgram/helloworld/$1";
controller
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class FirstProgram extends CI_Controller {
public function helloworld($param=''){
$data = array(
'title' => 'Title',
'heading' => 'Heading',
'message' => 'Message',
'param' => $param
);
echo $param;exit;
$this->load->view('FirstProgram', $data);
}
}
?>
答案 0 :(得分:3)
更改您的路线代码,只需为:any添加一个括号
$route['helloword/(:any)'] = "FirstProgram/helloworld/$1";