我使用下面的代码为我的网站,但它显示我如何发送ID到控制器笨
404:找不到网页。
路由
$route['class_name/function_name/(:num)'] = 'class_name/function_name/$1';
控制器。
public function function_name($Id)
{
print_r($Id); exit;
}
我使用下面的代码为我的网站,但它显示我如何发送ID到控制器笨
404:找不到网页。
路由
$route['class_name/function_name/(:num)'] = 'class_name/function_name/$1';
控制器。
public function function_name($Id)
{
print_r($Id); exit;
}
使用URI来从URL中提取ID: 以下是在文档的链接:http://www.codeigniter.com/userguide2/libraries/uri.html
我有可能创建一个简单的它可以帮助你
这是我的控制器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
这个根据你的服务器是动态执行
感谢您的回复。我在我的默认控制器中使用了您的代码,但无法正常工作。有什么帮助吗? 。配置文件中是否有任何设置? – Fadu
@Fadu,htaccess和mod_rewrite你启用它? –
并从你得到的地方'$ Id' –
不知道我在尝试使用google搜索。我也使用了$ this-> uri-> segment(3),但他们没有给我编号 – Fadu
您正在使用的东西类似于http://example.com/class_name/function_name/3的URL,还是你使用不同的格式? – gabe3886