2010-01-14 4 views

답변

5

물론 :

<?php require("Header.php"); ?> 

    <h1>Hello World</h1> 
    <p>I build sites without "smarty crap"!</p> 

<?php require("Footer.php"); ?> 
+0

당신은 현명하게 좋아하니? – Solar

+0

와우, 내가 편집 할 때 수정 한 내용을 수정했습니다. 내 잘못이야. – Sam152

+0

솔라리스, 나는 MVC를 좋아한다. :) – Sampson

2

내가 찾은 것 중 가장 가볍습니다.

include("header.php"); 
0

http://www.phpaddiction.com/tags/axial/url-routing-with-php-part-one/

은 멀리 멀리 최고의 튜토리얼 내가 발견했습니다. 이 소규모 프로젝트를 OOP로 전환하고 Procedural을 포기할 때이 레슨을 활용했습니다.

여기에 큰 경고가있어서 나에게 진지한 MVC가 필요하다면 CodeIgniter와 같이 테스트되고 안정적인 제품을 사용하는 것이 항상 좋습니다. 기본적으로이 혀를 사용하여 순수 PHP를 (모든 프레임 워크 명령을 다시 배우고 싶지 않았으며, 내가 포함하고 사용하기를 원하는 많은 클래스를 갖기 위해 MVC 해골을 만들었습니다.)

이 혀는 마일을 도왔습니다.

+0

http://stackoverflow.com/questions/1881571/php-mvc-fetching-the-view 이것은 내 원래 수수께끼였습니다 ... – DeaconDesperado

0

이메일에 대한 빠른 템플리트를 만들기 위해 생각한 작은 수업이 있습니다.

/** 
* Parses a php template, does variable substitution, and evaluates php code returning the result 
* sample usage: 
*  == template : /views/email/welcome.php == 
*   Hello {name}, Good to see you. 
*   <?php if ('{name}' == 'Mike') { ?> 
*    <div>I know you're mike</div> 
*   <?php } ?> 
*  == code == 
*   require_once("path/to/Microtemplate.php") ; 
*   $data["name"] = 'Mike' ; 
*   $string = LR_Microtemplate::parse_template('email/welcome', $data) ; 
*/ 
class Microtemplate 
{ 

    /** 
    * Micro-template: Replaces {variable} with $data['variable'] and evaluates any php code. 
    * @param string $view name of view under views/ dir. Must end in .php 
    * @param array $data array of data to use for replacement with keys mapping to template variables {}. 
    * @return string 
    */ 


    public static function parse_template($view, $data) { 
     $template = file_get_contents($view . ".php") ; 
     // substitute {x} with actual text value from array 
     $content = preg_replace("/\{([^\{]{1,100}?)\}/e", 'self::get_value("${1}", $data)' , $template); 

     // evaluate php code in the template such as if statements, for loops, etc... 
     ob_start() ; 
     eval('?>' . "$content" . '<?php ;') ; 
     $c = ob_get_contents() ; 
     ob_end_clean() ; 
     return $c ; 
    } 

    /** 
    * Return $data[$key] if it's set. Otherwise, empty string. 
    * @param string $key 
    * @param array $data 
    * @return string 
    */ 
    public static function get_value($key, $data){ 
     if (isset($data[$key]) && $data[$key]!='~Unknown') { // filter out unknown from legacy system 
      return $data[$key] ; 
     } else { 
      return '' ; 
     } 
    } 
}