如何使用php上的模板,如何在PHP中模板…正确的方法?

我开始理解在

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,但我想知道哪个和为什么

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值