php CodeIgniter “未找到您请求的页面。” 错误?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17633582/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 16:12:27  来源:igfitidea点击:

CodeIgniter "The page you requested was not found." error?

phpcodeigniter

提问by Ricardo

I'm having a problem with CodeIgniter. I've checked every possible solution on the internet and seems like nothing helps in my case. I'm not a big pro and it's my first time using CodeIgniter so don't be harsh with me.

我在使用 CodeIgniter 时遇到了问题。我已经检查了互联网上所有可能的解决方案,似乎对我的情况没有任何帮助。我不是专业人士,这是我第一次使用 CodeIgniter,所以不要对我太苛刻。

routes.php:

路线.php:

$route['default_controller'] = "page";
$route['404_override'] = '';

$route['(:num)'] = "page/index/";

page.php:

页面.php:

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Page extends CI_Controller {

    public function index($id=null) {

        $this->load->model('Image','',TRUE);
        $this->load->model('Banner','',TRUE);
        $image = $this->Image->getImageById($id);
        if (empty($image)) {
            show_404();
        }
        //db table `banner` always have three rows
        $banners=$this->Banner->getBanners();
        $data=array();
        $data['image']=$image;
        $data['banner']=$banners;
        $this->load->view('page_index', $data);
    }
}

回答by Saroj Dahal

I have read your problem. You have done mistake while saving the controller.

我已经阅读了你的问题。您在保存控制器时犯了错误。

It should be saved in capital i.e. Page.phpbut you have saved as page.php

它应该保存在资本中,即Page.php但您已保存为page.php

I think this will work out !

我想这会解决的!

回答by Ravinder Payal

If you have developed your application on Windows, you might have not set first character of Controllers and Models name as a capital character.

如果您在 Windows 上开发了您的应用程序,您可能没有将控制器和模型名称的第一个字符设置为capital character.

like /controllers/home.phpto /controllers/Home.php

/controllers/home.php/controllers/Home.php

On Linux file names are case sensitive.

在 Linux 上,文件名区分大小写。

Note:- This is a solution to a possible problem. There may be issues of mis configuration, server and path variables.

注意:- 这是对可能出现的问题的解决方案。可能存在配置错误、服务器和路径变量的问题。

回答by bdscorvette

Did you construct the parent? Public function _construct() { Parent::_construct(); }

你构造了父级吗?公共函数_construct() { Parent::_ construct(); }

回答by Ricardo

Thank you everyone, The problem was that i stated in page.php that if there is no images in the database it'll show 404 page:

谢谢大家,问题是我在page.php中声明,如果数据库中没有图像,它将显示404页面:

if (empty($image)) {
    show_404();
}

I've added two images to the DB and now it works.

我已经向数据库添加了两个图像,现在它可以工作了。

回答by semanticMike

This doesn't sound like a Codeigniter error. It could be your webserver configuration. Do you have a webserver and php server setup and configured on your machine? Have you configured an .htaccess file to replace "index.php"?

这听起来不像是 Codeigniter 错误。这可能是您的网络服务器配置。您是否在您的机器上设置并配置了网络服务器和 php 服务器?您是否配置了 .htaccess 文件来替换“index.php”?

回答by score

I am also quite new to codeigniter. This is what I would do at the beginning:

我对 codeigniter 也很陌生。这就是我一开始会做的事情:

  1. autoload database and configure the database.php file
  2. autoload helper file 'url', 'file'
  3. configure your base url "://yourhost/yourworkingfolder" (if you are working on local host)
  4. You need to route your page. Go to route.php, and give the name of your default controller page name and if it seems working than you r good to further with additional task.
  1. 自动加载数据库并配置database.php文件
  2. 自动加载帮助文件 'url', 'file'
  3. 配置您的基本网址“://yourhost/yourworkingfolder”(如果您在本地主机上工作)
  4. 您需要路由您的页面。转到 route.php,并提供您的默认控制器页面名称,如果它看起来有效,那么您可以进一步执行其他任务。

Please, correct me if I am wrong. I am a newbie to codeigniter. Thankx

如果我错了,请纠正我。我是 codeigniter 的新手。谢谢

回答by Amit Prajapati

the controller will uppercase first letter if you are using Unix server

如果您使用的是 Unix 服务器,控制器将大写第一个字母