Include view động trong PHP tùy thuộc vào querystring trên URL

isset: kiểm tra biến có được set hay không

$_GET[‘page’]: lấy value của querystring có tên là page

– Cộng chuỗi bằng “.=” để tạo ra link để include view thích hợp

[syntax type=”php”]<?php
error_reporting( E_ALL );
ini_set( “display_errors”, 1 );
$pageData = new stdClass();
$pageData->title = “Thomas Blom Hansen: Portfolio site”;
$pageData->content = include_once “views/navigation.php”;
$navigationIsClicked = isset($_GET[‘page’]);
if ($navigationIsClicked ) {
$fileToLoad = $_GET[‘page’];
//change one line to load page views dynamically
$pageData->content .=include_once “views/$fileToLoad.php”;
}
$page = include_once “templates/page.php”;
echo $page;[/syntax]

PHP: Include view động

Category: Uncategorized
0
3071 views

Join the discussion

Your email address will not be published. Required fields are marked *