Thursday, January 23, 2014

Problem with year dropdown

Hi guys!

I have a dropdown where you can choose an opening year of a themepark attraction.

Database

Column: opened
Type: year(4)
Null: no
Standard value: none

So far so good. Now I try to display a dropdown with year values between 1954 (opening park) and the current year + 1.

edit.ctp

echo $this->Form->inputs(array(
    'legend' => false,
    'name' => array(
        'label' => 'Name'
    ),
    'opened' => array(
        'type' => 'year',
        'label' => 'Year opening',
        'dateFormat' => 'Y',
        'minYear' => 1954,
        'maxYear' => date('Y') + 1,
        'empty' => 'Kies...'
    ),
    'show' => array(
        'type' => 'radio',
        'legend' => 'Show on website',
        'options' => array(
            'Y' => 'Ja',
            'N' => 'Nee'
        )
    )
));

But here comes my first problem. The dropdown output is a list with values from 2034 to 0 and that's not the kind of options I want. When I change the type to "date", the options do work great then. BUT then the selected value on edit is always "1970" (database says 1984). What could be the problem here?

My second problem occurs when saving the changes. Everytime I do so, I've got the error:

Error: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'Array' in 'field list'

I've debugged the request object and saw the following:

object(CakeRequest) {
params => array(
'plugin' => 'coaster_cms',
'controller' => 'attractions',
'action' => 'edit',
'named' => array(),
'pass' => array(
(int) 0 => '1'
)
)
data => array(
'Attraction' => array(
'name' => 'Boomerang',
'opened' => array(
'year' => '1984'
),
'show' => 'Y'
)
)
}

As you can see, the "opened" value send to the request object is an array. How can I change it so the data array have something like 'opened' => 1984 in it?

Thanks for helping me ;)

--
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 cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/groups/opt_out.

No comments: