我开始理解在
PHP中模板化的重要性.我正在使用
PHP本身作为模板引擎来避免学习任何新语言.虽然我对此有所了解,但我还是不清楚.我想知道专家做了什么.
我应该创建一个完整的页面模板,包括所有表格,表格和其他所有内容(包括页眉和页脚),或者我应该将所有表格,表格等放在他们自己的文件中,然后根据需要将它们添加到模板中.
这是一个清理事物的小例子……
我是不是该
a)创建一个包含所有表格,表格和其他元素的页面,并将其用作最终产品
// Set all the information
$template->title = $username;
$template->user_info = get_user($user_id);
$template->articles = get_articles($user_id);
$template->ads = random_ad($user_info);
// Load the template with everything already in it
$template->load('user_page.tpl')
$template->display();
要么
b)在自己的文件中创建每个表,表单,相关块元素,然后使用它们创建最终产品
// set the title and load the header template
$header['title'] = $username;
$template->load('header.tpl', $header);
// get the user info as an array and load into user profile template
$user_info = get_user($user_id);
$template->load('user_profile.tpl');
// load the new article form
$template->load('new_article_form.tpl');
// get the articles as an array of info and load into user articles template
$articles = get_articles($user_id);
$template->load('user_articles.tpl', $articles);
// get a random ad based on user info
$ads = random_ad($user_info);
$template->load('advertisements.tpl');
// load the footer template and display final page
$template->load('footer.php');
$template->display();
加载的每个文件都包含需要在最终页面上显示的一小部分内容.
因为不要重复你自己的技术,我会想B,但我想知道哪个和为什么