简单的PHP框架实现antoload,viewEngine
程序员文章站
2024-04-04 18:26:05
...
1. [代码]index.php 入口文件
<?php function __autoload($class){ include $class.'.php'; } $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('t.php', array('name'=>'aaaaaaaaaaa')); } }
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>