Janoo
(Pocak87)
September 19, 2012, 4:25am
1
Hy everyOne!
My first job in Yii, to create a pornsite (I’m doing this to my colleague, not for Me
So, my question:
How can I create a first page with a question: Are You over 18?,
I guess everybody know, this page must load always first if somebody click to this site.
What should I use?? beforeRender, or beforeAction…?
Some params: don’t want to overwrite their request to this page, and don’t want to put any code into every Controller
i woudl like check this authentication on one point
Thanks for answers, and sorry for my bad english
gbasto
(Goncalo Basto)
September 19, 2012, 8:33am
2
You have CWebApplication::beforeControllerAction() that is called before any controller action.
Janoo
(Pocak87)
September 19, 2012, 6:25pm
4
Hy!
I try to use this beforeControllerAction() , but it seem not to work
i put it into my index.php
require_once($yii);
$app = Yii::createWebApplication($config);
$app->beforeControllerAction('Videos', 'elmult');
$app->run();
but nothing happen… I have this controller, and that has this action "elmult", and the accessRules allow to anyone to use it!
Any idea? ?
seenivasan
(Chellamnivas)
September 19, 2012, 8:04pm
5
Dear Janu
I hope the following is helpful
views/site/verification.php
<?php
echo CHtml::encode('Are You 18 years or more old?');
echo CHtml::beginForm();
echo CHtml::radioButtonList('ageCheck','1',array(1=>'YES',2=>'NO'),array('separator'=>''));
echo '</br>';
echo CHtml::submitButton('submit');
echo CHtml::endForm();
?>
SiteController.php
public function actionCheckAge()
{
if(isset($_POST['ageCheck']))
{
if($_POST['ageCheck']==1)
{
Yii::app()->user->setState('permission','adulthood');
$this->redirect(array('site/index'));
}
else Yii::app()->user->setState('permission','childhood');
}
$this->render('verification');
}
main/configuration.php
Add a application behavior as a property not as a component
...........................................................
'behaviors'=>array(
'class'=>'application.components.applicationBehavior',
),
................................................................
components/applicationBehavior.php
<?php
class applicationBehavior extends CBehavior
{
private $_owner;
public function events()
{
return array(
'onBeginRequest'=>'catchRequest',
);
}
public function catchRequest()
{ $this->_owner=$this->getOwner();
if(!Yii::app()->user->hasState('permission') || Yii::app()->user->getState('permission')=="childhood" )
{
$this->_owner->catchAllRequest=array('site/checkAge');
}
}
}
?>
regards