2010-01-14 127 views

回答

5

肯定的:

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

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

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

你喜欢smarty吗? – Solar 2010-01-14 17:24:40

+0

哎呀,我做了一个编辑,以修复在编辑时修复的问题。我的错。 – Sam152 2010-01-14 17:24:58

+0

太阳能,我喜欢MVC :) – Sampson 2010-01-14 17:25:27

2

这是我能找到的最轻的一个。

include("header.php"); 
1

尝试在看看Twig被法比安斯基Potencier。

0

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

远远地占据了最好的教程中,我已经找到。我利用这一课将我的小型项目切换到OOP并放弃了Procedural。

这里一个重要的提醒和东西,所以让我意识到 - 如果你需要一个严重的MVC,它始终是更好地去与测试的,稳定的像笨。我基本上使用这个技巧来构建一个MVC框架来将我的纯PHP挂起来(我不想重新学习所有的框架命令,并且我有很多我想要包含并继续使用的类。 )

这啧啧啧啧,

+0

http://stackoverflow.com/questions/1881571/php-mvc-fetching-the-view 这是我原来的难题... – DeaconDesperado 2010-01-14 17:50:58

0

这里有一个很小的类,我想出了办发e-mail一些快速的模板。

/** 
* 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 '' ; 
     } 
    } 
}