mega-crazy
mega-crazy

Reputation: 858

Phalcon PHP still going to default template even after view->pick

Hello guys i have a basic class like this

class IndexController extends ControllerBase
{


    public function onConstruct(){

    }

    public function indexAction()
    {

        return $this->view->pick(array("login/login"));         
    }   

}

I want it to render whats there in the login folder and login.volt

Thing is, it is rendering it , but also it is rendering what is there in index.volt and which has the following

<!DOCTYPE html>
<html>
    <head>
        <title>Phalcon PHP Framework</title>
    </head>
    <body>
        {{ content() }}
    </body>
</html>

So im getting double html double bodys etc

Can someone tell me why this is happening and/or suggest a fix. Thanks guys

Upvotes: 2

Views: 912

Answers (4)

Jack jdeoel
Jack jdeoel

Reputation: 4584

You can set action view only by setRenderLevel

public function indexAction()
{
    $this->view->setRenderLevel(View::LEVEL_ACTION_VIEW);
    return $this->view->pick(array("login/login"));         
}   

Upvotes: 0

Saurabh Chandra Patel
Saurabh Chandra Patel

Reputation: 13594

There are two way to use view in phalcon

$this->view->pick(array('login/login')); // with  layout 

$this->view->pick('login/login'); // without layout

Upvotes: 0

user1061169
user1061169

Reputation:

Try to use setMainView method

class IndexController extends ControllerBase
{


    public function onConstruct(){

    }

    public function indexAction()
    {

        return $this->view->setMainView("login/login");         
    }   

}

setMainView method use to set the default view. Just put the view name as parameter. http://docs.phalconphp.com/en/latest/api/Phalcon_Mvc_View.html

Upvotes: 1

John C
John C

Reputation: 666

Remove the return keyword. I believe it is fetching the view you want and then returning it into the base template.

Upvotes: 0

Related Questions