Мета теги сохраняются в базе данных в соответствующих полях 'meta_k' и 'meta_d' выводятся через свойства модели на страницу, в head Layouts/main.php нет.
Контроллер SiteController содержит следующий код:
Код: Выделить всё
<?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'=>0x1F476C,
'foreColor' => 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'
$model = $this->loadModel();
$this->render('index',array('meta_k'=>CHtml::encode($model->meta_k),'meta_d'=>CHtml::encode($model->meta_d)));
}
/**
* 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 actionOnline()
{
$model=new OnlineForm;
if(isset($_POST['OnlineForm']))
{
$model->attributes=$_POST['OnlineForm'];
if($model->validate())
{
//$headers="From: ".Yii::app()->params['contactEmail']."\r\nReply-To: ".Yii::app()->params['contactEmail'];
//$mail = mail(Yii::app()->params['contactEmail'],'Онлайн заявка',$model->name."\n".$model->product."\n".$model->contact,$headers);
$html = 'ФИО: '.CHtml::encode($model->name);
$html .= 'Наименование товара: '.CHtml::encode($model->product);
$html .= 'Контактная информация: '.CHtml::encode($model->contact);
$mail = $this->sendEmail(Yii::app()->params['contactEmail'], Yii::app()->params['contactEmail'],'Онлайн заявка',$html);
if($mail === true){
Yii::app()->user->setFlash('contact','Спасибо, Ваша заявка успешно отправлена.');
$this->refresh();
}
}
}
$this->render('online',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);
}
/**
* Returns the data model based on the primary key given in the GET variable.
* If the data model is not found, an HTTP exception will be raised.
* @param integer the ID of the model to be loaded
*/
public function loadModel()
{
if(isset($_GET['id'])) {
$criteria=new CDbCriteria;
$criteria->select = 'meta_k';
$criteria->select = 'meta_d';
$criteria->condition = 'id=:id';
$criteria->params = array(':id'=>$_GET['id']);
$model=Categories::model()->find($criteria);
return $model;
}else{
if($model===null)
throw new CHttpException(404,'The requested page does not exist.');
}
}
}
Код: Выделить всё
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="keywords" content="<?=$meta_k;?>" />
<meta name="description" content="<?=$model->meta_d;?>" />
<link rel="stylesheet" type="text/css" href="/css/all.css" media="all" />
<link rel="stylesheet" type="text/css" href="/css/form.css" media="all" />
<script type="text/javascript" src="/js/jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="/js/main.js"></script>
<title><?php echo CHtml::encode($this->pageTitle); ?></title>
</head>