我在我的网站上使用以下代码,但它显示了我
404:找不到页面。
路由
$route['class_name/function_name/(:num)'] = 'class_name/function_name/$1';
控制器
public function function_name($Id)
{
print_r($Id); exit;
}
答案 0 :(得分:1)
使用URI从URL中提取id: 以下是文档中的链接:http://www.codeigniter.com/userguide2/libraries/uri.html
答案 1 :(得分:0)
我创造了一个简单的可能它可以帮助你
这是我的控制器welcome.php来自codeigniter
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Welcome extends CI_Controller {
/**
* Index Page for this controller.
*
* Maps to the following URL
* http://example.com/index.php/welcome
* - or -
* http://example.com/index.php/welcome/index
* - or -
* Since this controller is set as the default controller in
* config/routes.php, it's displayed at http://example.com/
*
* So any other public methods not prefixed with an underscore will
* map to /index.php/welcome/<method_name>
* @see http://codeigniter.com/user_guide/general/urls.html
*/
public function index()
{
$this->load->view('welcome_message');
}
public function test1($ID) {
echo $ID;
}
public function test2($ID, $ID2) {
var_dump($ID, $ID2);
}
public function test() {
echo 'test';
}
}
这是我的路线
$route['default_controller'] = 'welcome';
$route['welcome/test1/(:num)'] = 'welcome/test1/$1';
$route['welcome/test/(:num)/(:num)'] = 'welcome/test/$1/$2';
工作时访问它的示例
https://192.168.248.209/stackoverflow/welcome/test2/1/3 https://192.168.248.209/stackoverflow/welcome/test1/1
根据您的服务器实现,这个是动态的