Php CodeIgniter默认视图
我有一个叫佩奇的控制器Php CodeIgniter默认视图,php,codeigniter,Php,Codeigniter,我有一个叫佩奇的控制器 <?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/
<?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);
}
}
我不熟悉php框架,不知道如何实现这一点。任何帮助都将不胜感激。Codeigniter路由的工作方式是将
example.com/test
指向控制器文件夹中名为test.php
的控制器的索引函数
以下是codeigniter url路由的约定:
http://www.example.com/controller/function_in_that_controller/parameters/in/that/function
在
http://www.example.com/controller/
,默认调用索引函数;因为在控制器之后的url中没有定义函数。Codeigniter路由的工作方式是将example.com/test
指向控制器文件夹中名为test.php
的控制器的索引函数
以下是codeigniter url路由的约定:
http://www.example.com/controller/function_in_that_controller/parameters/in/that/function
在http://www.example.com/controller/
,默认调用索引函数;因为在控制器之后的url中没有定义任何函数。更改
$route['(:any)'] = 'page/$1';
到
改变
到
好的,那么如何通过页面控制器的索引函数加载测试页面呢?我尝试了
example.com/page/index/test
和example.com/index/test
和example.com/page/test
,但似乎没有任何效果try example.com/index.php/test,如果有效,请查看codeigniter文档中的.htaccess文件,以便能够随时访问页面,那么,如何通过页面控制器的索引函数加载测试页面呢?我尝试了example.com/page/index/test
和example.com/index/test
和example.com/page/test
,但似乎没有任何效果try example.com/index.php/test,如果有效,请从codeigniter文档中获取.htaccess文件,以便能够在我这样做时访问页面,现在我如何访问该页面?我试过http://www.example.com/test
没有骰子。希望视图目录中有test.php
文件。首先在http://www.example.com/index.php/test
。如果有效,那么检查.htaccess
文件设置和config.php
文件设置。我已经这样做了,现在如何访问页面?我试过http://www.example.com/test
没有骰子。希望视图目录中有test.php
文件。首先在http://www.example.com/index.php/test
。如果有效,则检查.htaccess
文件设置和config.php
文件设置。
$route['(:any)'] = 'page/index/$1';