如何连接控制器以在PHP OOP中查看? [英] How to connect controller to view in PHP OOP?

查看:52
本文介绍了如何连接控制器以在PHP OOP中查看?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

现在我正在使用PHP OOP编程,没有框架,我开始创建Blog应用程序.首先,我创建一个Bootstrap文件,然后处理所有情况,然后创建一个用于处理登录和发布类的Handler类,现在在登录处理程序类中显示值,然后如何连接到视图部分.

Now i am using PHP OOP Programming, without framework, I start to create a Blog Application. First i create a Bootstrap file then all cases should be handle through this, then i create a Handler class for handle the login and post classes, right now display the value in login handler class, then how to connect into view part.

推荐答案

初始化理解的基本思想:)如果您希望视图类更强大,则需要对其进行进一步开发.

Basic idea to initialize your understanding :) if you want the view class to be more powerful, you need to develop it further.

view.php

<?php
class View {    
    function __construct($tpl) {
        include $tpl;
    }
}
?>

handler.php

<?php
class Handler {
    function __construct() {}
    function process($post) {
        echo $post;
    }
}
?>

bootstrap.php

<?php
require('view.php');
require('handle.php');

$view = new View('form.html');
$handler = new Handler();

if (isset($_POST['login'])) {
    $handler->process($_POST['username']);
}
?>

这篇关于如何连接控制器以在PHP OOP中查看?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆