Last active
August 29, 2015 14:06
-
-
Save vanchelo/08a93ca7a04cd05949ff to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php namespace App\Http\Controllers; | |
| use App\Classes\Title; | |
| class MyController extends Controller | |
| { | |
| /** | |
| * @var Title | |
| */ | |
| protected $title; | |
| function __construct(Title $title) | |
| { | |
| $this->title = $title; | |
| } | |
| public function index() | |
| { | |
| $this->title->prepend('Главная страница'); | |
| } | |
| } | |
| class MyController extends Controller | |
| { | |
| /** | |
| * @var Title | |
| */ | |
| protected $title; | |
| function __construct() | |
| { | |
| $this->title = app('title'); | |
| } | |
| public function index() | |
| { | |
| $this->title->prepend('Главная страница'); | |
| } | |
| } | |
| class MyController extends Controller | |
| { | |
| public function index(Title $title) | |
| { | |
| $title->prepend('Главная страница'); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php namespace App\Providers; | |
| use Illuminate\Support\ServiceProvider; | |
| use App\Classes\Title; | |
| class AppServiceProvider extends ServiceProvider | |
| { | |
| public function register() | |
| { | |
| $this->app->singleton('App\Classes\Title', function () | |
| { | |
| // Здесь можно из конфига значение подставить | |
| return new Title('Название сайта'); | |
| }); | |
| $this->app->bind('title', 'App\Classes\Title'); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <title>{{ app('title') }}</title> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| class Title | |
| { | |
| protected $values = []; | |
| protected $delimiter; | |
| function __construct($value, $delimiter = ' :: ') | |
| { | |
| $this->values[] = $value; | |
| $this->delimiter = $delimiter; | |
| } | |
| public function append($value = '', $delimiter = null) | |
| { | |
| $this->values[] = $delimiter ?: $this->delimiter; | |
| $this->values[] = $value; | |
| } | |
| public function prepend($value = '', $delimiter = null) | |
| { | |
| array_unshift($this->values, $value, $delimiter ?: $this->delimiter); | |
| } | |
| public function render() | |
| { | |
| return implode('', $this->values); | |
| } | |
| public function last() | |
| { | |
| return end($this->values); | |
| } | |
| public function first() | |
| { | |
| return reset($this->values); | |
| } | |
| function __toString() | |
| { | |
| return $this->render(); | |
| } | |
| } |
Author
Author
Как использовать?
$title = new Title('Название сайта', ' - ');
$title->prepend('Категория');
$title->prepend('Статья');По умолчанию delimiter (разделитель значений) ::
И пишем в шаблоне
<title><?= $title ?></title>На выходе получаем такой код
<title>Статья - Категория - Название сайта</title>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How to Use?
Default values
delimiteris::And in View Layer
This will render