mark2bra
(Mark2bra)
May 10, 2014, 11:15am
1
I was requested to write a code in beforeValidate function which will block users from creating an account on Sunday , Monday and Tuesday.
I wrote the following code based on this documentation:
http://www.yiiframework.com/doc/api/1.1/CDateFormatter#formatDayInWeek-detail
$today=date("Y-m-d");
$day=Yii::app()->dateFormatter->formatDayInWeek('EEEE', $today);
if($day='Saturday')
Yii::app()->getController()->redirect('index.php?r=site/closed');
However it tell me that:
Any ideas why? (it accepted just format , but its not what I need)
JbalTero
(Jbaltero)
May 10, 2014, 2:40pm
2
Try this one.
$today=date("Y-m-d");
$day = date('l', strtotime($today));
if($day=='Saturday')
Yii::app()->getController()->redirect('index.php?r=site/closed');
mark2bra
(Mark2bra)
May 10, 2014, 4:01pm
3
Seems like it works , but only when I added another =
if($day=='Saturday')
Whats the 1 stands for?
Thank you very much Jbal !
Cheers ,
Mark.
JbalTero
(Jbaltero)
May 11, 2014, 3:33pm
4
Oh I forgot to add another ‘=’.
it’s not 1, it’s ‘l’. It’s the formatting options for date() function.
jkofsky
(Jkofsky)
May 12, 2014, 4:16am
5
I was requested to write a code in beforeValidate function which will block users from creating an account on Sunday , Monday and Tuesday.
I wrote the following code based on this documentation:
http://www.yiiframework.com/doc/api/1.1/CDateFormatter#formatDayInWeek-detail
$today=date("Y-m-d");
$day=Yii::app()->dateFormatter->formatDayInWeek('EEEE', $today);
if($day='Saturday')
Yii::app()->getController()->redirect('index.php?r=site/closed');
However it tell me that:
Any ideas why? (it accepted just format , but its not what I need)
$dayOfWeek = date('w');
select $dayOfWeek {
case 0: //Sunday
case 1: //Monday
case 2: //Tuesday
//Oh No you can't <img src='http://www.yiiframework.com/forum/public/style_emoticons/default/smile.gif' class='bbc_emoticon' alt=':)' />
Yii::app()->getController()->redirect('/site/closed');
break;
default:
// Ok you can do it.
Yii::app()->getController()->redirect('/site/open');
break;
}
skapeyi
(Kapeyisamson)
May 12, 2014, 2:05pm
6
JbalTero:
Oh I forgot to add another ‘=’.
it’s not 1, it’s ‘l’. It’s the formatting options for date() function.
Hey read about the PHP Operators ‘=’ is an assignment operator, while ‘==’ is a comparison operator.
I hope that makes sense!