• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 372
  • Last Modified:

PHP question

I have a very basic question - just started using cakephp and i am having trouble getting my index page to render.

I have two pages: 1 is the index page and one is the expiration page. I have a date set, and if the current date does not exceed the $expiration_date, the index page is supposed to render. I keep getting a 404 error - am I doing anything obviously wrong?
<?php

class ftaf2Controller extends AppController {
	/**
	 * @access	public
	 * @var		string
	 */
	public $name = 'ftaf2';

	/**
	 * @access	public
	 * @var		array
	 */
	public $uses = array(
		'Coupon'
	);
	
	/**
	 * @access	public
	 * @var		array
	 */
	public $components = array(
        'Session',
		'EmailDeployment'
	);

	/**
	 * beforeFilter callback
	 *
	 * @since	0.3
	 * @access  public
	 * @return  void
	 */
	public function beforeFilter() {

		$expiration_date = '2011-12-06 00:00:00';

		if (date('Y-m-d H:i:s') > $expiration_date) {
			$this->render('expired');
			exit;
		}

 public function index() {
		 } 
	
	}

?>

Open in new window

0
lvollmer
Asked:
lvollmer
  • 2
  • 2
  • 2
  • +1
2 Solutions
 
seanmccullyCommented:
First you are not comparing dates  correctly, use the strtotime function to compare dates.
0
 
lvollmerAuthor Commented:
can you show me an example of what should be done?
0
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

 
Chris HarteThaumaturgeCommented:
You cannot compare date strings like that, convert them to timestamps

$expiration_date = '2011-12-06 00:00:00';

$ex_date = strtotime($expiration_date);

$now = strtotime(date('Y-m-d H:i:s'));

if ($now > $ex_date)
{
    $this->render('expired');
    exit;
}
0
 
Hugh McCurdyCommented:
MunterMan makes a good point.  I also think it would help you to learn if you saw what was going on.

Put these printf commands before your if statement.

printf ( "Raw now = %s<br />\n", date ( 'Y-m-d H:i:s'));

(If you are running PHP from the command prompt instead of using a web server, you can leave out the <br />)

printf ( "Cooked now = %s<br />\n", now );
printf ( "ex_date = %s<br />\n", $ex_date );
0
 
Hugh McCurdyCommented:
Oh, remove the printf statements after you understand what is happening.
0
 
lvollmerAuthor Commented:
thanks
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 2
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now