如何加载动态$ content取决于使用此php结构的codeigniter中获取url
<?php
include_once "header.php";
$content ='index-1.php';
if(isset($_GET['p'])){
switch($_GET['p']){
case "room" : $content="room.php" ; break;
case "room-page" : $content="room-page.php" ; break;
case "book" : $content="book.php" ; break;
case "about" : $content="about.php" ; break;
case "contact" : $content="contact.php" ; break;
}
}
include $content;
include_once "footer.php"; ?>
答案 0 :(得分:0)
Bellow控制器功能:
<?php
public function index()
{
//$data['page']['content'] = 'room';
$data['page']['content'] = $this->input->get('page_name'); //like page name is "room"
$this->load->view('welcome', $data);
}
?>
在视图文件夹中然后welcome.php
:
<?php
$this->load->view('header');
$this->load->view($page['content']);
$this->load->view('footer');
?>
答案 1 :(得分:0)
假设用户已请求您的主站点网址。
控制器功能
public function index()
{
$data['page_name'] = $this->input->get('pageName');
$this->load->view('index', $data);
}
视图文件夹中的文件,在我的情况下 index.php 应该如下所示
<?php
include 'header.php';
include .$page_name.'.php';
include 'footer.php';
?>
希望这能解决您的问题。