[英]How to set a title in Cell/Header directory in cakePHP ?
I am using CakePHP 3.0 and I am using inside the Cell/Header directory a display for the header. 我正在使用CakePHP 3.0,并且在Cell / Header目录中使用了标题显示。
<div id="header"> <div class="header-title"> <h2><?php echo (isset($pageTitle)) ? $pageTitle : 'Test'?></h2> </div> </div>
This code snippet runs perfectly and on every page. 此代码段可以在每个页面上完美运行。 I am trying to set the $pageTitle dynamically.
我试图动态设置$ pageTitle。 This means that I am trying to set it for every page differently.
这意味着我要为每个页面设置不同的设置。 I have set inside the UsersController.php
我已经在UsersController.php中设置了
$this->set('pageTitle', 'Nebojsa');
In index method. 在索引方法中。 But when I go to the url /users/index , this page title stays 'test'.
但是,当我转到url / users / index时,此页面标题仍为“ test”。 I have also tried to assign the value inside the Template/Users/index.ctp
我也尝试在Template / Users / index.ctp中分配值
<?= $this->assign('pageTitle', __('Users')); ?>
But it won't work. 但这是行不通的。 What am I doing wrong ?
我究竟做错了什么 ? Could you maybe point me in the right direction, where should I look ?
你能指出我正确的方向,我应该去哪里看?
Between view templates and layouts you can use: 在视图模板和布局之间,可以使用:
<?= $this->assign('pageTitle', __('Users')); ?>
And get the value back in any other template or layout using: 并使用以下方法在其他任何模板或布局中获取值:
<?= $this->fetch('pageTitle') ?>
As far as setting the title from the controller your code is correct. 就从控制器设置标题而言,您的代码是正确的。
$this->set('pageTitle', 'Nebojsa');
<?php echo (isset($pageTitle)) ? $pageTitle : 'Test'?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.