douyuefu1372
2016-03-06 17:38
浏览 69
已采纳

如何在Yii中使用模板引擎?

I want to write a program with Yii so that users can have their template.

My solution is that every user has a record in a DB to keep a customized template like HTML code and some syntax like Smarty or Twig.

How can I use PHP to get that records and just print it on the screen and my template engine extracts syntax and shows best results? Is that possible or not? How should I do this?

Really you know if you save php codes in database, when you print them into a file, php codes you saved in database don't run. For me the most important thing is that to save template in database whit php commands and then echo them in a file and php code run same usually.

But is is important to use smarty or twig and don't let users add php codes directly.

图片转代码服务由CSDN问答提供 功能建议

我想用Yii编写一个程序,以便用户可以拥有他们的模板。

我的解决方案是每个用户都在数据库中有一条记录来保存自定义模板,如HTML代码和一些语法,如Smarty或Twig。

如何使用PHP来获取 记录,只需将其打印在屏幕上,我的模板引擎提取语法并显示最佳结果? 这有可能吗? 我该怎么做?

真的你知道如果你把PHP代码保存在数据库中,当你把它们打印成文件时,保存在数据库中的php代码就不会运行了。 对我来说最重要的是在数据库中保存模板whit php命令然后在文件中回显它们并且php代码通常运行相同。

但使用smarty或twig非常重要,不要让用户直接添加php代码。

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • douqian1517 2016-03-07 14:20
    已采纳

    I found my answer. Just save every thing in database and when load them use eval() function. See documents in php and w3school.

    评论
    解决 无用
    打赏 举报
查看更多回答(1条)

相关推荐 更多相似问题