I cannot set title_for_layout
in the PagesController that comes by default with CakePHP 1.3.
I am using the following code in the display function:
$this->set( title_for_layout , some title );
What am I doing wrong?
I cannot set title_for_layout
in the PagesController that comes by default with CakePHP 1.3.
I am using the following code in the display function:
$this->set( title_for_layout , some title );
What am I doing wrong?
In your controller, the corresponding value is $this->pageTitle
.
UPDATE
Oops, as noted in the comments, this is the 1.2 solution. 1.3 possibilities (after doing some research) include:
$title_for_layout
is being echoed in the layout$this->set()
code in the view rather than in the controllerIf you d like to mimic the behavior of cake 1.2, you can do the following:
In your app_controller, create the following method:
in app/app_controller.php (you may need to create this file if you haven t already)
public $pageTitle;
public function beforeRender() {
$this->set( title_for_layout , $this->pageTitle);
}
Then in any of your action methods, you may then use the pageTitle as you would in 1.2.
public function index() {
$this->pageTitle = Some Title ;
}
The beforeRender() method will be called after your controllers have finished processing, but prior to the layout being rendered, thus allowing you to set variables for the layout.
In the action method, try this:
function index()
{
$this->pageTitle= Your Title ;
}
Just thought I d add to any new people finding this solution, you can do $this->set( title , $title);
in CakePHP 1.3 inside the controller and the title will be rendered automatically.
You can use :
$this->assign( title , Some title );
and in ctp :
<title><?= $this->fetch( title ); ?></title>
It work in CakePHP 3.0
For CakePHP 3.x,
you can follow the advice here
Essentially,
Inside UsersController.php
:
$this->set( title , Login );
Inside src/Template/Layouts/default.ctp
above the $this->fetch( title );
write:
if (isset($title)) {
$this->assign( title , $title);
}
Use beforeRender()
instead. Put the following in AppController:
class AppController extends Controller {
var $content;
function beforeRender() {
$this->set( content ,$this->content);
}
}
And in the controller, you can just do:
function index() {
$this->content[ title ] = 123 ; }
That ll do the trick.
In CakePHP, it seems like a lot of functions can take their arguments as nested, multidimensional arrays, or as dotted strings: $this->MyModel->contain(array( Something , Something.Else , ...
I ve got a cakephp app that I m trying to get to serve up the Pages::404 function (and corresponding view) whenever Cake encounters any error (missing controller, action, etc). What s the best way to ...
I am going to be builiding a site like ebay - with all the features of ebay. Please note my payment method is limited to paypal. What would be the best PHP framework to use to build this quickly, ...
I am wondering if there is a way to specify the date format in the forms created using CakePHP s $form->inputs(); Please note that this is not the individual $form->input() but instead $form->inputs() ...
I am writing a CakePHP 1.2 app. I have a list of people that I want the user to be able to filter on different fields. For each filterable field, I have a drop down list. Choose the filter ...
In my CakePHP app, I m pulling in the results of a table called Timesheets . This table has an athlete_id and a few split times for a race. I need to do some calculations on one athlete s times ...
How would I represent the following in a CakePHP model? Product ======= product_id .... Cart ==== cart_id .... Carts_Products ============== cart_id product_id quantity
I am a beginning Cake user and trying to do some work on an already existing application. Running into a problem when I create a new controller. I have created StoreController and when I try to call ...