Inside Layouts/default.ctp you will see something like this at line 39:
<div class="header-title">
<span><?= $this->fetch('title') ?></span>
</div>
fetch
suggests that it is a view block. I couldn't find this view block anywhere.
Currently it just displays the capitalized plural form of controller. Meaning to say if you are at /users/add
, the fetch('title');
gives you 'Users'
I want to change it. So I tried the following:
$this->set('title', 'Login');
in the /users/login
controller action.
Did not work.
I also tried
$this->assign('title', 'Login');
in the /users/login
controller action.
I get this error message:
Call to undefined method App\Controller\UsersController::assign()
I read the docs and from here
I get
Assigning a block’s content is often useful when you want to convert a view variable into a block. For example, you may want to use a block for the page title, and sometimes assign the title as a view variable in the controller:
Emphasis mine.
This suggests that you can use assign
inside controller. I think I have proven that this is false.
Perhaps there is a typo in the documents. Please advise how I can set the title