Blogger Information
Blog 13
fans 0
comment 0
visits 8821
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
1204 1205作业 (补)
文永
Original
578 people have browsed it

实例

<?php


namespace mvc;



require 'Model.php';

require 'View.php';


class Container1
{

    protected $instance = [];


    public function bind($alias, \Closure $process)
    {
    
        $this->instance[$alias] = $process;
    }

    public function make($alias, $params=[])
    {
       return call_user_func_array($this->instance[$alias], []);
    }
}


$container = new Container1();

$container->bind('model', function () {return new Model();});
$container->bind('view', function () {return new View();});


class Facade
{
    protected static $container = null;
    protected static $data = [];


    public static function initialize(Container1 $container)
    {
        static::$container = $container;
    }

    public static function getData()
    {
        static::$data = static::$container->make('model')->getData();
    }


    public static function fetch()
    {
        return static::$container->make('view')->fetch(static::$data);
    }
}

class Student extends Facade
{

}


class Controller5
{
    public function __construct(Container1 $container)
    {

        Student::initialize($container);
    }

    public function index()
   {

        Student::getData();


       return Student::fetch();
   }
}


$controller = new Controller5($container);
echo $controller->index();

image.png


image.png

image.png


image.png




image.png



image.png


image.png


image.png


image.png


image.png


image.png


image.png


image.png


image.png

Correcting teacher:天蓬老师天蓬老师

Correction status:qualified

Teacher's comments:代码真干净, 一行注释都没有
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!