开发者

CakePHP Show different View if user is not logged in

开发者 https://www.devze.com 2023-02-28 19:40 出处:网络
I have the following code in my home_controller: <?php class HomeController extends AppController { var $name = \'Home\';

I have the following code in my home_controller:

<?php

class HomeController extends AppController
{
    var $name = 'Home';

    var $uses = array();

    function index ()
    {
        $this->set('title_for_l开发者_运维知识库ayout', 'Welcome to CreatHive');
    }

}

?>

Unlike normal authentication whereby you would redirect the user to a login form if they try and access certain actions or controllers I just want to show a different view for my index method on my homecontroller. So if the user is NOT logged in then show splash.ctp and if they are logged in then show index.ctp

Thanks


public function index() {
    $this->set('title_for_layout', 'Welcome to CreatHive');
    if (!$this->Auth->user()) {
        $this->render('splash');
    }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消