Iam facing strange problem. Only text in view file(index.php) is visible. And default layout 'main.php' is unable to load.
I haven't disturbed anything. Only column1 and column2 files are deleted from default installation/settings.
Can some one guide me in this regards
Thanks in advance
Page 1 of 1
Default Layout 'main' is not loaded/called
#2
Posted 18 April 2010 - 03:20 AM
Did you made sure that the main.php layout file exists under protected/views/layouts/main.php? what is your directory structure? do you use modules?
#3
Posted 18 April 2010 - 03:25 AM
It was running fine. All of a sudden it happend. Yes 'main.php' is in its default location.
#4
Posted 18 April 2010 - 03:29 AM
You have to set $this->layout = 'main' in the Controller.php (assuming you just deleted column1 and column2 files but forget to delete links to them).
#5
Posted 18 April 2010 - 03:39 AM
Here is my controller labelled as "SiteController.php"
Can you guide me further.
Thanks
<?php
class SiteController extends Controller
{
/**
* Declares class-based actions.
*/
public function actions()
{
return array(
// captcha action renders the CAPTCHA image displayed on the contact page
'captcha'=>array(
'class'=>'CCaptchaAction',
'backColor'=>0xFFFFFF,
),
// page action renders "static" pages stored under 'protected/views/site/pages'
// They can be accessed via: index.php?r=site/page&view=FileName
'page'=>array(
'class'=>'CViewAction',
),
);
}
/**
* This is the default 'index' action that is invoked
* when an action is not explicitly requested by users.
*/
public function actionIndex()
{
// renders the view file 'protected/views/site/index.php'
// using the default layout 'protected/views/layouts/main.php'
$this->render('index');
}
/**
* This is the action to handle external exceptions.
*/
public function actionError()
{
if($error=Yii::app()->errorHandler->error)
{
if(Yii::app()->request->isAjaxRequest)
echo $error['message'];
else
$this->render('error', $error);
}
}
/**
* Displays the contact page
*/
public function actionContact()
{
$model=new ContactForm;
if(isset($_POST['ContactForm']))
{
$model->attributes=$_POST['ContactForm'];
if($model->validate())
{
$headers="From: {$model->email}\r\nReply-To: {$model->email}";
mail(Yii::app()->params['adminEmail'],$model->subject,$model->body,$headers);
Yii::app()->user->setFlash('contact','Thank you for contacting us. We will respond to you as soon as possible.');
$this->refresh();
}
}
$this->render('contact',array('model'=>$model));
}
/**
* Displays the login page
*/
public function actionLogin()
{
$model=new LoginForm;
// if it is ajax validation request
if(isset($_POST['ajax']) && $_POST['ajax']==='login-form')
{
echo CActiveForm::validate($model);
Yii::app()->end();
}
// collect user input data
if(isset($_POST['LoginForm']))
{
$model->attributes=$_POST['LoginForm'];
// validate user input and redirect to the previous page if valid
if($model->validate() && $model->login())
$this->redirect(Yii::app()->user->returnUrl);
}
// display the login form
$this->render('login',array('model'=>$model));
}
/**
* Logs out the current user and redirect to homepage.
*/
public function actionLogout()
{
Yii::app()->user->logout();
$this->redirect(Yii::app()->homeUrl);
}
}
Can you guide me further.
Thanks
#6
Posted 18 April 2010 - 03:46 AM
I mean "protected/components/Controller.php" file. Check it's layout property.
#7
Posted 18 April 2010 - 03:53 AM
Thanks it solved my problem.
Can you guide me where can I get knowledge about importance of "protected/components/Controller.php"
Can you guide me where can I get knowledge about importance of "protected/components/Controller.php"
#8
Posted 18 April 2010 - 04:08 AM
As you can see, SiteController extends it instead of extending CController.
All other controllers should extend Controller too, because it defines some common properties like "breadcrumbs" and "menu" used by all your controllers (you must define them per each controller otherwise).
It also sets default layout to "column1.php", but since you are using own layout, you can omit that line.
All other controllers should extend Controller too, because it defines some common properties like "breadcrumbs" and "menu" used by all your controllers (you must define them per each controller otherwise).
It also sets default layout to "column1.php", but since you are using own layout, you can omit that line.
Share this topic:
Page 1 of 1

Help















