Nhúng template, và sử dụng object trong PHP

File template: template.tpl.php

[syntax type=”php”]<?php
return “<!DOCTYPE html>
<html>
<head>
<title>$pageData->title</title>
<meta http-equiv=’Content-Type’ content=’text/html;charset=utf-8′ />
</head>
<body>
$pageData->content
</body>
</html>”;[/syntax]

File Index: index.php

[syntax type=”php”]<?php
error_reporting( E_ALL );
ini_set( “display_errors”, 1 );
$myName = “Tran Ky Phat”;
$pageData = new stdClass(); // Khởi tạo object
$pageData->title = “Hello Title”; //Modify thuộc tính của object
$pageData->content = “Hello Content”;
$page = include_once “template.tpl.php”; // inlcude template

echo $page;
echo “<h1>Welcome to my website.$myName</h1>”;

[/syntax]

Hello World PHP

Category: PHP
0
788 views

Join the discussion

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