定制 fantomx1/view-locator 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

fantomx1/view-locator

Composer 安装命令:

composer require fantomx1/view-locator

包简介

template locator

README 文档

README

View locator class, for locating views/templates relatively the to processing logic controller/model, especially used in frameworks or independent framework-agnostic extensions Following the standard frameworks way of reflecting the controller's name as subfolders inside the views (MVC) folder, containing a template for each executing logic (Controller/Widget) action eg. CRUD.

    Controllers
       SiteController
     Views
       Site
          create.php (C-reate)
          index.php  (R-ead)
          edit.php   (U-pdate)
          list.php   (D-delete)

Usage

    $tl = new TemplateLocator();
    $path = $tl->seek($this);
    
    $path = $path .'/'.$template.'.php';
    #####################################
    
    $tl = new TemplateLocator();
    $path = $tl->getRelative()->setViewsDir('../../twig/views')->seek($this);
    $path = $path .'/'.$template.'.php';

$this - passing the $this param to the $seek method, is a controller in which is this library used in, to reflect the templates path relatively to it. (TODO: better to add it to some fluent interface method chaining)

In full context

protected function render($template, array $vars)
{

    $tl = new ViewLocator();
    $path = $tl->setViewsDir('./templates')->seek($this);

    extract($vars);
    include $path.''.$template.'.php';
}

Using fantomx1\ViewLocatorRenderTrait for handling rendering overhead in libraries from the shelf eg. in real wold context..

private $viewsDir = './views/';

<?php


namespace fantomx1\toolmasterforeman\examples\ComposerAssetsInstallerTool;

use fantomx1\toolmasterforeman\ToolMasterForemanAbstract;
use fantomx1\ViewLocatorRenderTrait;

class ComposerAssetsInstallerTool extends ToolMasterForemanAbstract
{

    use ViewLocatorRenderTrait;


    /**
     *   the 
     * protected function getViewsDir()
     * {
     * return $this->getDefaultViewsDir();
     * }
     * @return string
     */
    protected function getViewsDir()
    {
        return $this->getDefaultViewsDir("./views");
    }


    public function actionIndex()
    {
        $this->render("index", ['test'=>1]);
    }

}

统计信息

  • 总下载量: 22
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 1
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: Unknown
  • 更新时间: 2020-07-15

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固