为什么我的ci一直访问的是默认控制器???
新手,刚学习ci,好多不懂。一上来路由就把我搞得好郁闷!!!ci默认控制器是welcome,如:http://yong_hu.avazutracking.net/play_ci/index.php/welcome/index;我自定义了一个控制器User,在浏览器其中输入http://yong_hu.avazutracking.net/play_ci/index.php/user/index;结果一直还是访问的是默认的welcome控制器。百度了下,有人说你改一下config目录下的 routes.php中的$route['default_controller'] = 'welcome';这个是可以。但是不能我每次调试其他的控制器都去改一下吧 Hex 发表于 2016-10-11 10:16nginx 参考 https://www.nginx.com/resources/wiki/start/topics/recipes/codeigniter/ 设置一下
#usernobody;
worker_processes1;
#error_loglogs/error.log;
#error_loglogs/error.lognotice;
#error_loglogs/error.loginfo;
#pid logs/nginx.pid;
events {
worker_connections1024;
}
http {
include mime.types;
default_typeapplication/octet-stream;
client_max_body_size 20M; #修改此处上传大小为自己实际需要的大小
#log_formatmain'$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
#access_loglogs/access.logmain;
sendfile on;
#tcp_nopush on;
#keepalive_timeout0;
keepalive_timeout65;
#gzipon;
server {
listen 80;
server_namewww.yhuweb.com;
#charset koi8-r;
#access_loglogs/host.access.logmain;
location / {
root D:/wnmp/www;
indexindex.html index.php;
# if (-f $request_filename) {
# expires max;
# break;
# }
# if (!-e $request_filename) {
# rewrite ^/(.*)$ /index.php/$1 last;
# }
}
#error_page404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504/50x.html;
location = /50x.html {
root D:/wnmp/www;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location /phpmyadmin {
alias D:/wnmp/www/phpmyadmin;
index index.php;
}
location ~ \.php$ {
root D:/wnmp/www;
fastcgi_pass 127.0.0.1:9090;
fastcgi_indexindex.php;
fastcgi_paramSCRIPT_FILENAMED:/wnmp/www$fastcgi_script_name;
include fastcgi_params;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# denyall;
#}
}
# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_namesomenamealiasanother.alias;
# location / {
# root html;
# indexindex.html index.htm;
# }
#}
# HTTPS server
#
#server {
# listen 443 ssl;
# server_namelocalhost;
# ssl_certificate cert.pem;
# ssl_certificate_keycert.key;
# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout5m;
# ssl_ciphersHIGH:!aNULL:!MD5;
# ssl_prefer_server_cipherson;
# location / {
# root html;
# indexindex.html index.htm;
# }
#}
}
*********************************************************
这是我的nginx全部配置。
$config['base_url'] = 'http://'.$_SERVER['HTTP_HOST'].'/play_ci';
ci命名为play_ci,放在根目录下;
$config['uri_protocol'] = 'AUTO';
AUTO和REQUEST_UR设置I都试过了;
$route['default_controller'] = 'cismarty';routes.php下默认控制器的配置
*********************************************************
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Cismarty extends CI_Controller {
function __construct()
{
parent::__construct();
}
function index()
{
$this->test();
}
public function test()
{
$this->tpl->assign("content","恭喜你smarty安装成功!");
$this->tpl->display('smarty_view.html');
}
}
这是我自定义的控制器代码;
自己在浏览器中访问时
http://www.yhuweb.com/play_ci/index.php/cismarty/test
结果是404 Not Found 本帖最后由 alben_001 于 2016-10-12 11:16 编辑
主要是因为缺少server环境变量引起的
=> work.mading.cn
=> work.mading.cn
=> D:/xampp/htdocs/workspace/
=> D:/xampp/htdocs/workspace/
=> D:/xampp/htdocs/workspace/zuowen/CodeIgniter-3.1.0/index.php
=> /zuowen/CodeIgniter-3.1.0/
=> /zuowen/CodeIgniter-3.1.0/index.php
=> /zuowen/CodeIgniter-3.1.0/index.php
看看你的 server 和这几个参数有什么区别,然后给自己的项目手动添加server,查看是否可以解决问题,如果可以再调整nginx配置
燃雲 发表于 2016-10-12 04:58
除此以外,看看User有无index()。
LNMP还要看目录及文件的系统及Nginx访问权等等。
defined('BASEPATH') OR exit('No direct script access allowed');
class User extends CI_Controller {
public function __construct()
{
parent::__construct();
}
public function index()
{
echo "hello ,everyone!";
}
}
******************
有的,文件目录我直接设成777了 希望大神救我!!!!都快折腾死我了:'( 你的 CI 版本是什么? 最新的3.1.0的 path_info有开启吗 萧然 发表于 2016-10-9 22:57
最新的3.1.0的
可以尝试下更改 config.php 里的 URI 协议,不要使用 AUTO。 原来是$config['uri_protocol'] = 'REQUEST_URI';,我改成AUTO,两个试过了都没用,还可以改成什么吗 萧然 发表于 2016-10-10 19:19
原来是$config['uri_protocol'] = 'REQUEST_URI';,我改成AUTO,两个试过了都没用,还可以改成什么吗 ...
都没用。。。。
你这个问题太奇怪了,没有你的环境我也说不好了,很抱歉,建议你用 wamp 吧,直接配好的环境。 我的是nginx1.8 我用的是wnmp,公司的是lnmp