tags:

views:

35

answers:

2

Hello,

I have the following code in a CakePHP Controller:

var $searchCondition = array(
    'Item.date >' => date('Y-m-d', strtotime("-2 weeks"))  // line 11
);

var $paginate = array(
    'conditions' => $itemCondition,
    'limit' => 25,
);


function index() {
    $this->set('applications',$this->paginate());
}

I am getting the following error:

Parse error: syntax error, unexpected '(', expecting ')' in D:\xampplite\htdocs\myApp\app\controllers\applications_controller.php on line 11

Does anyone knows what it means? I've double checked and the syntax seems to be right.

Thanks

+2  A: 

You can only use constant values when initializing class properties. You cannot use functions here. You'll have to do something like this:

var $searchCondition = array(
    'Item.date >' => null
);

function beforeFilter() {   // or __construct
    $this->searchCondition['Item.date >'] = date('Y-m-d', strtotime("-2 weeks"));
}
deceze
A: 

Hello dornad,

maybe you are really better off placing your variables in a more local place - like your controller actions, instead of a callback like beforeFilter(). In addition, there is a superfluos comma in this line:

'limit' => 25,

Kind regards, Benjamin.

benjamin