douzhen1234 2016-08-03 15:18
浏览 83
已采纳

CodeIgniter默认视图

I've got this controller called Page

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

class Page extends CI_Controller {

    /**
     * Index Page for this controller.
     *
     * Maps to the following URL
     *      http://example.com/index.php/welcome
     *  - or -
     *      http://example.com/index.php/welcome/index
     *  - or -
     * Since this controller is set as the default controller in
     * config/routes.php, it's displayed at http://example.com/
     *
     * So any other public methods not prefixed with an underscore will
     * map to /index.php/welcome/<method_name>
     * @see https://codeigniter.com/user_guide/general/urls.html
     */
    public function index($page = 'home')
    {
        if ( ! file_exists(APPPATH.'views/'.$page.'.php'))
        {
                // Whoops, we don't have a page for that!
                show_404();
        }

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

        $this->load->view('templates/header', $data);
        $this->load->view($page, $data);
        $this->load->view('templates/footer', $data);
    }
}

but currently it only loads the home.php page by going to http://www.example.com/

I'm trying to make it so if I go to example.com/test it would load test.php

Here are my routes

$route['default_controller'] = 'page';
$route['(:any)'] = 'page/$1';

I am new to php frameworks, and I'm not sure how to achieve this. Any help would be much appreciated.

  • 写回答

2条回答 默认 最新

  • dqlxtv1452 2016-08-03 15:24
    关注

    Codeigniter routing works in a way that it would point example.com/test to a the index function of a controller called Test.php in your controllers folder.

    The following is the conventions for codeigniter url routing:

    http://www.example.com/controller/function_in_that_controller/parameters/in/that/function
    

    At http://www.example.com/controller/, the index function is called by default; since no function is defined in the url after the controller.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 请提供一个符合要求的网页链接。
  • ¥20 用HslCommunication 连接欧姆龙 plc有时会连接失败。报异常为“未知错误”
  • ¥15 网络设备配置与管理这个该怎么弄
  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码