如果我的整个网站使用apps / view / layouts / default.ctp中指定的default.ctp布局,如何仅更改主页布局以使用homepage.ctp并使用default.ctp保留网站的其余部分?
Copy the /cake/libs/controller/pages_controller.php
into your /app/controller/
dir and do either of the following:
display()
to switch the layout if 'home' is requested: if ($page == 'home') $this->layout = 'homepage';
home()
method (or named however you like) in which you set $this->layout
and re-route the /
route in /app/config/routes.php
to use this new method. Edit:
In summary, you need some custom method in which you'll set $this->layout = 'homepage'
, that's all. You can do this in any of your controllers at any point, reusing the PagesController
is just the most convenient and conventional way to do it in Cake.
The above answer is now out of date, but gives the right approach.
In modern versions of CakePHP, the controller he asks you to make is already present and is:
/app/Controller/PagesController.php
I had a template called "loggedoff", and added this as follows, just before the $this->render()
command (approx line 73).
$this->layout = 'loggedoff';
This works fine:
class RegistrationsController extends AppController {
public $helpers = array('Html', 'Form', 'Time');
public $components = array('Session');
public function login() {
$this->layout = 'empty';
}
}
Just set the desired layout in the controller function.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.