Home > php教程 > PHP源码 > 简单的PHP框架实现antoload,viewEngine

简单的PHP框架实现antoload,viewEngine

PHP中文网
Release: 2016-05-25 17:09:41
Original
1088 people have browsed it

1. [代码]index.php 入口文件    

<?php
function __autoload($class){
    include $class.&#39;.php&#39;;
}
$t = new tController();
$t->index();
Copy after login

2. [代码]Controller.php 核心控制器

<?php
class Controller {
    function render($temple, $arr){
        extract($arr);
        ob_start();
        include $temple;
        $content = ob_get_contents();
        ob_end_clean();
        echo $content;
    }    
}
Copy after login

3. [代码]tController.php 普通控制器

<?php
class tController extends Controller{
    function index(){
        $this->render(&#39;t.php&#39;, array(&#39;name&#39;=>&#39;aaaaaaaaaaa&#39;));
    }
}
Copy after login

4. [代码]t.php 视图文件

<html>
        <header>
                <title></title>
        </header>
        <body>
                <?php  echo @$name; ?>
                <form method="post" action="">
                        用户名:<input name="username" type="text" value=""><br>
                        密码:   <input name="password" type="password"><br>
                        <input name="submit" type="submit" value="提交">
                </form>
        </body>
</html>
Copy after login

                   

                   

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template