PHPackages                             fantomx1/view-locator - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Templating &amp; Views](/categories/templating)
4. /
5. fantomx1/view-locator

ActiveLibrary[Templating &amp; Views](/categories/templating)

fantomx1/view-locator
=====================

template locator

0.9(5y ago)0221PHP

Since Jul 15Pushed 5y ago1 watchersCompare

[ Source](https://github.com/FantomX1/viewLocator)[ Packagist](https://packagist.org/packages/fantomx1/view-locator)[ RSS](/packages/fantomx1-view-locator/feed)WikiDiscussions master Synced today

READMEChangelog (1)DependenciesVersions (3)Used By (1)

viewLocator
===========

[](#viewlocator)

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
=====

[](#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
===============

[](#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..
-----------------------------------------------------------------------------------------------------------------------------

[](#using-fantomx1viewlocatorrendertrait--for-handling-rendering-overhead-in-libraries-from-the-shelf--eg-in-real-wold-context)

private $viewsDir = './views/';

```
