zenify / title-component
此包已被废弃且不再维护。未建议替代包。
Nette 的标题组件
5.0.3
2019-01-08 07:18 UTC
Requires
- php: >=5.5
- nette/application: ~2.2
- tracy/tracy: ~2.2
Requires (Dev)
- nette/bootstrap: ~2.2
- nette/robot-loader: ~2.2
README
安装
通过 Composer
$ composer require zenify/title-component
在 config.neon
中注册扩展
extensions: - Zenify\TitleComponent\DI\TitleExtension
使用方法
注入到展示器
class Presenter ... { /** * @inject * @var Zenify\TitleComponent\TitleControlFactory */ public $titleControlFactory; /** * @return Zenify\TitleComponent\TitleControl */ protected function createComponentTitle() { return $this->titleControlFactory->create(); } }
在模板中渲染
<head> ... {control title} </head>
添加标题
通过注解
class HomepagePresenter ... { /** * @title Contact us */ public function renderContact() { } }
或通过方法
class ProductPresenter ... { public function startup() { // set main title for whole app $this['title']->set('Zenify'); parent::startup(); } /** * @param int */ public function renderDetail($id) { $product = ...($id); $this['title']->append('Detail of ' . $product->name); // change separator if you like $this['title']->setSeparator(' - '); } }
这将导致
Zenify - Detail of product ...
支持翻译器
class HomepagePresenter ... { /** * @title homepage.contact.title */ public function renderContact() { } /** * @param string */ public function renderDetail($name) { $this['title']->set(['user.detail.name', NULL, ['name' => $name]]); } }