我有一点问题
这是我的控制器CapturistaCtrl.php:
#particles-js{
position:fixed;
top: 0px;
left: 0px;
}
这是我的routes.php
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class CapturistaCtrl extends CI_Controller {
public function index(){
echo "index";
}
public function alta(){
echo "alta";
}
}
在config.php上:
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;
$route['default_controller'] = 'Welcome';
$route['capturista'] = 'CapturistaCtrl';
和.htaccess
$config['base_url'] = 'http://localhost/captura';
$config['index_page'] = '';
如果我输入此网址:http://localhost/captura/capturista我会收到文字&#34; index&#34;显示,这意味着我的控制器上的index()方法有效,但如果我放http://localhost/captura/capturista/alta我得到404页。
答案 0 :(得分:0)
使用正则表达式捕获组(...)
。
<强>尝试:强>
$route['capturista(.*)'] = 'CapturistaCtrl$1';
替代,使用:任何通配符。
$route['capturista/(:any)'] = 'CapturistaCtrl/$1';
$route['capturista'] = 'CapturistaCtrl/index';
答案 1 :(得分:0)
****controller code****
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
/**
*
*/
class CapturistaCtrl extends CI_controller
{
public function index(){
echo "index";
}
public function alta(){
echo "alta";
}
}
**routes.php**
$route['default_controller'] = 'welcome';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;
$route['capturista'] = 'CapturistaCtrl';
$route['capturista/(:any)'] = 'CapturistaCtrl/$1';
// (or any one )$route['capturista/alta'] = 'CapturistaCtrl/alta';
**.htaccess**
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
</IfModule>
**config.php**
$config['index_page'] = 'index.php';
remove (index.php)
$config['index_page'] = '';
$config['uri_protocol'] = 'index.php';
remove (index.php)
$config['index_page'] = '';