• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

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

php 搞代码 3年前 (2022-01-25) 24次浏览 已收录 0个评论
文章目录[隐藏]

<body>

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>

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

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

首页的welcome_message.PHP依然能正确显示,但是一旦调用自己写的控制器就报错404:

这是我自己写的控制器:

<code class="lang-PHP"><?phpini_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');                    $d<em style="color:transparent">本@文来源[email protected]搞@^&代*@码网(</em><q>搞代gaodaima码</q>ata = $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>

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

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

回复内容:

<body>

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>

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

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

首页的welcome_message.PHP依然能正确显示,但是一旦调用自己写的控制器就报错404:

这是我自己写的控制器:

<code class="lang-PHP"><?phpini_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>

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

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

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

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

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


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:apache – CentOS上部署PHP框架CodeIgniter,调用控制器的时候出现404错误如何解决?

喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址