In that case use SQL functions instead. e.g.: NOW You can do this: 'datestart >= NOW()'
On Mon, Jul 15, 2013 at 5:12 PM, euromark <[email protected]> wrote: > Jep, as you experienced you cannot use dynamic stuff in the "static" part > of php classes > You need to overwrite constructor for this. > > > Am Montag, 15. Juli 2013 16:55:23 UTC+2 schrieb WhyNotSmile: > >> In my Model, I'm trying to associate 2 different things with a Course, >> using hasMany. The idea is that there are 'Courseinstances', which are >> just sets of dates on which the Course runs, and 'Courseinstancesupcoming', >> which are future dates only. I came up with the following (in Course.php): >> >>> public $hasMany = array( >>> 'Courseinstance' => array( >>> 'className' => 'Courseinstance', >>> 'foreignKey' => 'course_id', >>> 'order' => 'datestart ASC' >>> ), >>> 'Courseinstanceupcoming' => array( >>> 'className' => 'Courseinstance', >>> 'foreignKey' => 'course_id', >>> 'order' => 'datestart ASC', >>> 'conditions' => array( >>> 'datestart > ' => date('Y-m-d H:i:s') >>> ) >>> ) >>> ); >> >> >> Now, I'm not sure if this is a good thing to be even trying to do, but >> when I run it, I get the following error: >> >> *Error: *syntax error, unexpected '(', expecting ',' or ';' >>> *File: *C:\wamp\www\RNNI\site\**app\Model\Course.php >> >> >> I tried various things, but got the same error. Then I tried adding the >> following line: >> >> >> var $date = date('Y-m-d H:i:s'); >> >> >> and this is now throwing an error instead (same error, but now on this >> line instead of the hasMany line). >> >> >> If I do >> >> >> var $date = 'testing'; >> >> >> >> instead, it copes fine. Is there something which prevents me from using >> the PHP date() function in a model in this way? >> >> >> And if anyone can suggest a solution to the initial problem of having 2 >> types of objects in the hasMany, that'd also be good, but it's not so >> urgent, as I can work around that one. >> >> >> Thanks in advance for any help! >> > -- > Like Us on FaceBook https://www.facebook.com/CakePHP > Find us on Twitter http://twitter.com/CakePHP > > --- > You received this message because you are subscribed to the Google Groups > "CakePHP" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To post to this group, send email to [email protected]. > Visit this group at http://groups.google.com/group/cake-php. > For more options, visit https://groups.google.com/groups/opt_out. > > > -- Renan Gonçalves aka renan.saddam Software Engineer at TrueServer B.V. CakePHP Core Developer W: renangoncalves.com T: twitter.com/renan_saddam M: +31 (0)6 4662 1860 L: Amsterdam, The Netherlands -- Like Us on FaceBook https://www.facebook.com/CakePHP Find us on Twitter http://twitter.com/CakePHP --- You received this message because you are subscribed to the Google Groups "CakePHP" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/cake-php. For more options, visit https://groups.google.com/groups/opt_out.
