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

简单的PHP框架实现antoload,viewEngine

PHP中文网
PHP中文网Original
2016-05-25 17:09:411090browse

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

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

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;
    }    
}

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

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

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>

                   

                   

Statement:
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