I cant figure out what is wrong with the following code:
class ArticlesController extends AppController{
var $name = 'Articles';
// Variable $today is defined here so it can be used
// in other functions in this same class
var $today = date('Y-m-d H:i:s',strtotime('now'));
var $helpers = array('Video');
function frontpageArticles(){
$articles = $this->Article->find(
'all',
array(
'conditions' => array(
'Article.published' => 1,
'Article.publish_date <=' => $today // USED HERE
)
)
)
);
return $articles;
}
// ...
}
I am getting the following error message:
Parse error: syntax error, unexpected '(', expecting ',' or ';' in /home/XXXXXXXX/public_html/app/controllers/articles_controller.php on line 10
And this is in LINE 10 var $today = date('Y-m-d H:i:s',strtotime('now'));
Thanks,
To elaborate further on what Julien’s answer stated, you can’t use functions in variable assignments in a class declaration, you can of course when you’re defining normal variables.
A way around this would be to assign your values in the constructor, like so:
Just a side note,
varis PHP4 syntax, so if you’re using PHP5 I would highly suggest that you use the access modifiers ie.public/private/protectedto define both your fields and methods based on how they will be used.