dongquan0024 2017-02-15 15:34
浏览 88
已采纳

在我的MVC结构中放置模板的位置? 在哪里定义?

I have the following structure in my MVC:

1) app
    1. controllers
        Home.class.php
    2. core
        App.class.php
        Controller.class.php
    3. models
        User.class.php
    4. views
        - home
            index.php
        .htaccess
        init.php
2) public
    1. css
    2. js
    .htaccess
    index.php

Now I'd like to implement templating too. I've used the following code before to use templating in my projects.

<?php
    class Template
    {
        private $assignedValues = array();
        private $tpl;

        public function __construct($_path = '')
        {
            if(!empty($_path)){
                if(file_exists($_path)){
                    $this->tpl = file_get_contents($_path);
                }
                else{
                    echo '<b>Template Error:</b> File Inclusion Error.';
                }
            }
        }

        public function assign($_searchString, $_replaceString)
        {
            if(!empty($_searchString)){
                $this->assignedValues[strtoupper($_searchString)] = $_replaceString;
            }
        }

        public function show()
        {
            if(count($this->assignedValues > 0)){
                foreach ($this->assignedValues as $key => $value) {
                    $this->tpl = str_replace('{'.$key.'}', $value, $this->tpl);
                }
            }

            echo $this->tpl;

        }

    }

So where would I have to put this class? And where would be the folder with the templates in it? I've also used the default file with defines in it. What would be the beste place to drop my defines file?

  • 写回答

1条回答 默认 最新

  • doushi7394 2017-02-15 15:43
    关注

    Why not in:

    app/views/layouts/your-template.php

    It makes sense to me to keep it with the rest of your "view" based structure as it is a template.

    This is also the way Laravel (a php framework) does it.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分
  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题