apache - CentOS上部署PHP框架CodeIgniter,调用控制器的时候出现404错误如何解决?

WBOY
Release: 2016-06-06 20:46:12
Original
1358 people have browsed it

CI版本为3.0 dev。

在本地虚拟机CentOS 6.3 和 windows上部署好后,

本机数据库能正确连接
本机controllers能正确调用,通过URL也能正确访问

<code class="lang-PHP"># /application/config/config.php
$config['base_url'] = '';
$config['index_page'] = 'index.php';
$config['uri_protocol'] = 'AUTO';
$config['url_suffix'] = '';
$config['enable_hooks'] = FALSE;
$config['subclass_prefix'] = 'MY_';
</code>
Copy after login
Copy after login

======================================
但是部署到阿里云服务器上后

index.php->
controllers welcome.php->
views welcome_message.php->

首页的welcome_message.PHP依然能正确显示,但是一旦调用自己写的控制器就报错404:
apache - CentOS上部署PHP框架CodeIgniter,调用控制器的时候出现404错误如何解决?

这是我自己写的控制器:

<code class="lang-PHP"><?php ini_set("error_reporting",E_ALL ^ E_NOTICE);
class Userinfo extends CI_Controller{
            function userinfo(){
                    parent::__construct();
                    $this->load->database();
                    $this->load->helper('url');
                }
            function index()
            {
                    $id=$_POST['id'];
                    $this->load->model('getmodel');
                    $data = $this->getmodel->getone($id);
                    $output = json_encode($data);
                    $userinfo = '[{"msgtype":"3"}]';
                    $query['getuser_output'] = $userinfo.$output;
                    $this->load->view('welcome_message',$query);
                }
}

/* End of file userinfo.php */
/* Location: ./application/controllers/userinfo.php */
</code>
Copy after login
Copy after login

PHP版本是5.3.3 默认配置
apache版本是2.2.15 默认配置
Centos版本是 6.3 x64 关闭了SELINUX

请问大概是哪个环节出了问题?

回复内容:

CI版本为3.0 dev。

在本地虚拟机CentOS 6.3 和 windows上部署好后,

本机数据库能正确连接
本机controllers能正确调用,通过URL也能正确访问

<code class="lang-PHP"># /application/config/config.php
$config['base_url'] = '';
$config['index_page'] = 'index.php';
$config['uri_protocol'] = 'AUTO';
$config['url_suffix'] = '';
$config['enable_hooks'] = FALSE;
$config['subclass_prefix'] = 'MY_';
</code>
Copy after login
Copy after login

======================================
但是部署到阿里云服务器上后

index.php->
controllers welcome.php->
views welcome_message.php->

首页的welcome_message.PHP依然能正确显示,但是一旦调用自己写的控制器就报错404:
apache - CentOS上部署PHP框架CodeIgniter,调用控制器的时候出现404错误如何解决?

这是我自己写的控制器:

<code class="lang-PHP"><?php ini_set("error_reporting",E_ALL ^ E_NOTICE);
class Userinfo extends CI_Controller{
            function userinfo(){
                    parent::__construct();
                    $this->load->database();
                    $this->load->helper('url');
                }
            function index()
            {
                    $id=$_POST['id'];
                    $this->load->model('getmodel');
                    $data = $this->getmodel->getone($id);
                    $output = json_encode($data);
                    $userinfo = '[{"msgtype":"3"}]';
                    $query['getuser_output'] = $userinfo.$output;
                    $this->load->view('welcome_message',$query);
                }
}

/* End of file userinfo.php */
/* Location: ./application/controllers/userinfo.php */
</code>
Copy after login
Copy after login

PHP版本是5.3.3 默认配置
apache版本是2.2.15 默认配置
Centos版本是 6.3 x64 关闭了SELINUX

请问大概是哪个环节出了问题?

把这个controller的index设置成default页面呢
404一般是路由错了

弱弱的问一句和pathinfo有关系吗

把你的 方法:userinfo() 改成:__construct()

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template