Not signed in (Sign In)
Welcome Guest!
Want to take part in these discussions? If you have an account, sign in now.
If you don't have an account, apply for one now.
    • CommentAuthortamboo
    • CommentTimeFeb 18th 2008 edited
     
    Hi,
    Recently, I am working almost with Akelos Framework.

    I'm just saving null string('').
    There seems to be a difference in the save when create and update.

    When creating it, can you save the null string('')?
    Because the NULL is not contained in input tag.
    I hope,

    <input name="item[value]" type="radio" value="" />

    Item: id int, value string

    <?php

    function add(){
    $this->Item->setAttribute(array('value' => ''));
    $this->Item->save();
    }
    // value => null

    function edit(){
    $this->Item->setAttribute(array('id' => 1, 'value' => ''));
    $this->Item->save();
    }
    // value => ''

    ?>
    •  
      CommentAuthorbermi
    • CommentTimeFeb 18th 2008
     

    Shouldn't you be calling?

    $this->Item->setAttributes(array('value' => ''));
    

    setAttributes in plural?

    • CommentAuthortamboo
    • CommentTimeFeb 18th 2008
     
    I'm sorry.
    It is this description mistake.

    $this->Item->setAttributes(array('value' => ''));

    But, this result is the same.
    •  
      CommentAuthorbermi
    • CommentTimeFeb 18th 2008
     

    You should use helpers to create your radio inputs, as they add a hidden value before the radio for those situations when its not checked.

    • CommentAuthortamboo
    • CommentTimeFeb 18th 2008 edited
     

    The selected radiobutton cannot be released. Then, I adding selection 'no select' item.

    Is it a specification that cannot add the null string(not NULL)? update is OK.

    I'm just make a ActiveFormHelper extends FormHelper. It is automatically makes the form tags and the selection items from the database.

    SelectItem Model: id int, value string, title string, category ... 1, 1, 1 minute 2, 3, 3 minute 3, 5, 5 minute 4, 10, 10 minute 5, null, no select <- I hope save null string(not NULL)

    $this->SelectItem->setAttributes(array('value'=>'', 'title'=>'no select'));
    $this->SelectItem->save();
    

    Output from SelectItem.

    class ActiveFormInstanceTag extends AkFormHelperInstanceTag
    {
        function to_select_radio_tag($select_items, $options)
        {
            $select_radio = '';
            foreach ($select_items as $value => $text){
                $select_radio .= parent::to_radio_button_tag($value, $options).
                $text.'&nbsp;&nbsp;';
            }
            return $select_radio;
        }
    }
    

    Output html.

    < html>
    <input name="search[min]" type="radio" value="1" /> 1 minute
    <input name="search[min]" type="radio" value="3" /> 3 minute
    <input name="search[min]" type="radio" value="5" /> 5 minute
    <input name="search[min]" type="radio" value="10" /> 10 minute
    <input name="search[min]" type="radio" /> No select              <- if select this.
    </html>
    

    Result:

    echo $this->params['search']['min']  =>  'on';
    
    • CommentAuthorKaste
    • CommentTimeFeb 22nd 2008
     

    Is it a specification that cannot add the null string(not NULL)?

    I dont think so.

    -> #123

    • CommentAuthortamboo
    • CommentTimeFeb 23rd 2008
     

    Thank you so much.

Add your comments
    Username Password
  • Format comments as