技术宅,fat-man

增加语言的了解程度可以避免写出愚蠢的代码

导航

个人觉得还可以的php代码,老大不买账

function pageFactory($path,$layout)
{
    $factorys = Array ("template/1.html"=>TemplatePage1);
    return new $factorys[$layout]($path,$layout);
}

class Page
{
    public $path = null; 
    public $layout = "";
    public $data = Array();
    
    public static function load($path)
    {
        
    }
    
    public function Page($path,$layout)
    {
        echo "page...";
        $this->path = $path;
        $this->layout = $layout;
    }
    
    public function show()
    {
        $fileHandler = fopen($this->layout, r);
        $html = fread($fileHandler, 1024);
        fclose($fileHandler);
        return $html;
    }
    
    public function save($data){}
}

class TemplatePage1 extends Page
{
    public function save($data)
    {
        $fileHandler = fopen($this->path,w);
        fwrite($fileHandler,json_encode(
                Array(
                    "layout" => $this->layout,
                    "data" => Array("title" => $data["title"],
                                    "content" => $data["content"])
                    )));
        fclose($fileHandler);
    }
}

 

posted on 2013-03-15 14:56  codestyle  阅读(247)  评论(0)    收藏  举报