duanqiao9541 2017-03-09 17:09
浏览 31
已采纳

Codeigniter 3路线不工作

I am setting up a CodeIgniter project and so far everything has been going well. All my routes and controllers are working correctly except for one. While I am new to CodeIgniter I have been programming in PHP for close to five years so I have a bit of experience. If anyone could take a look at the code samples below and let me know what I am doing wrong, that would be great.

Apparently the application does recognize the route, but it keeps complaining about its inability to find the URI.

Controller:

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

class Profile extends CI_Controller {
    function __construct() {
        parent::__construct();

        $this->load->helper('url');
    }

    public function Profile($page = 'profile-page')
    {
        if ( ! file_exists(APPPATH.'/views/'.$page.'.php'))
        {
            // Load error page
            show_404();
        }

        // Capitalize the first letter
        $data['title'] = ucfirst($page);
        $data['pageType'] = "profile-page";

        // Load pages
        $this->load->view('templates/header', $data);
        $this->load->view('templates/topbar', $data);
        $this->load->view('profile');
        $this->load->view('templates/footer', $data);
        //
    }
}

Next is my Routes:

$route['default_controller'] = 'home/home';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;

// All custom routes go below this line.

$route['contact'] = 'pages/contact';
$route['signup'] = 'auth/signup';
$route['login'] = 'auth/login';
$route['profile'] = 'profile/profile';

I have verified that all the view files are in their correct folders and there are no typos. However the Profile route keeps failing. All the other routes work correctly, except for the Profile route.

I have tried this on Windows 10 with XAMMP, Mac OS X Sierra with MAMP and CentOS 7 with Apache/PHP/MySQL.

Thanks.

  • 写回答

4条回答 默认 最新

  • dpdjpt5137 2017-03-10 09:50
    关注

    The problem is your code enters into this condition & it is not able to find the profile-page.php file at that path and showing error.As profile function is calling properly without any issue as i checked

    if ( ! file_exists(APPPATH.'/views/'.$page.'.php'))
            {
                echo "test";die;
                // Load error page
                show_404();
            }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 BV260Y用MQTT向阿里云发布主题消息一直错误
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序