2

I am using cakephp version 2.6 . My main issue is only view of a action is rendered ,but layout is not getting applied.It is happening on overall actions.Whether it is a server issue I have applied default layout in AppController.php ,but still not working

public function beforeFilter() {
       $this->layout = 'default';
}

Thanks in advance.

7
  • 1
    first of all deafult will loaded automatically. second if you want to do then do either in beforeRender() of App or go the particular action and there only write $this->layout = 'some other layout'; Commented Mar 17, 2016 at 11:19
  • I have used $this->layout = 'default' in respective actions, but some time it is getting applied and other time only view is rendered.When viewed source only view code is displayed,not of the layout. Commented Mar 17, 2016 at 11:24
  • @AsimKatamale have you any type of error like data base not connected etc. Commented Mar 17, 2016 at 12:24
  • No database errors, and the code works fine on my local server ,but not on LIVE server and LIVE server PHP version is 5.4 Commented Mar 17, 2016 at 12:53
  • Just imagine in case where we have added $this->autoRender = false OR $this->layout = null, that type of view is getting displayed, that also on some instances ,other time it works fine Commented Mar 17, 2016 at 13:09

1 Answer 1

1

If you use default.ctp as default layout means, then don't want include the following line.

$this->layout = 'default';

Because cakephp is render to "default.ctp" layout by default.

Incase you want some other layout "someotherlayout.ctp"

Call to method

$this->layout = 'someotherlayout';

Suppose, you don't need layout and need some of main content without layout. Make sure "ajax.ctp" in your layout folder.

$this->layout = 'ajax';

Suppose, you don't need layout and need some of main data without layout.

$this->autoRender = false;
//provide the data or redirect some other page
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.