龙盟编程博客 | 无障碍搜索 | 云盘搜索神器
快速搜索
主页 > web编程 > php编程 >

PHP 简单的PHP框架,实现antoload,viewEngine

时间:2015-03-28 02:26来源:网络整理 作者:网络 点击:
分享到:
简单的PHP框架,实现antoload,viewEngine 最近在学写MVC框架,各位看看就好了,哈哈PS:有兴趣学写MVC框架的可以看看这篇文章:http://my.oschina.net/u/131802/blog/82016**index.php 入口文件**[代码片段

最近在学写MVC框架,各位看看就好了,哈哈PS:有兴趣学写MVC框架的可以看看这篇文章:http://my.oschina.net/u/131802/blo g/82016

index.php 入口文件

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

Controller.php 核心控制器

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

tController.php 普通控制器

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

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>
精彩图集

赞助商链接