Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Phalcon\Forms\Element\Select::addOption() #1958

Merged
merged 3 commits into from Feb 2, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@
- Phalcon\Forms\Form::count() implemented via Zend API (#1765)
- Phalcon\Forms\Form optimizations (#1765)
- Phalcon\Forms\Element now implements Phalcon\Forms\ElementInterface (#1852)
- Fixed Phalcon\Forms\Element\Select::addOption() (#1955)
- Phalcon\Http:
- Phalcon\Http\Cookie can be used without sessions (#875)
- Phalcon\Http\Cookie does not ignore expire time (#897)
Expand Down
20 changes: 16 additions & 4 deletions ext/forms/element/select.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ PHP_METHOD(Phalcon_Forms_Element_Select, __construct){
}

phalcon_update_property_this(this_ptr, SL("_optionsValues"), options TSRMLS_CC);
PHALCON_CALL_PARENT_NORET( phalcon_forms_element_select_ce, this_ptr, "__construct", name, attributes);
PHALCON_CALL_PARENT_NORET(phalcon_forms_element_select_ce, this_ptr, "__construct", name, attributes);

PHALCON_MM_RESTORE();
}
Expand Down Expand Up @@ -141,11 +141,23 @@ PHP_METHOD(Phalcon_Forms_Element_Select, getOptions){
*/
PHP_METHOD(Phalcon_Forms_Element_Select, addOption){

zval *option;
zval **option, *values, *tmp;

phalcon_fetch_params(0, 1, 0, &option);
phalcon_fetch_params_ex(1, 0, &option);
PHALCON_ENSURE_IS_ARRAY(option);

values = phalcon_fetch_nproperty_this(getThis(), SL("_optionsValues"), PH_NOISY TSRMLS_CC);

phalcon_update_property_array_append(this_ptr, SL("_optionsValues"), option TSRMLS_CC);
ALLOC_ZVAL(tmp);
if (Z_TYPE_P(values) != IS_ARRAY) {
MAKE_COPY_ZVAL(option, tmp);
}
else {
add_function(tmp, *option, values TSRMLS_CC);
}

Z_SET_REFCOUNT_P(tmp, 0);
phalcon_update_property_this(getThis(), SL("_optionsValues"), tmp TSRMLS_CC);
RETURN_THISW();
}

Expand Down
18 changes: 18 additions & 0 deletions ext/tests/issue-1955.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
--TEST--
Phalcon\Forms\Element\Select::addOption() does not work - Fix Phalcon\Forms\Element\Select::addOption()
--SKIPIF--
<?php include('skipif.inc'); ?>
--FILE--
<?php
new Phalcon\DI\FactoryDefault();
$selection = new \Phalcon\Forms\Element\Select("selection");
$selection->addOption(array('id'=>'1','value'=>'Apple'));
$selection->addOption(array('2'=>'Orange'));
echo $selection->render(array('multiple'=>'yes')), PHP_EOL;
?>
--EXPECT--
<select id="selection" name="selection" multiple="yes">
<option value="2">Orange</option>
<option value="id">1</option>
<option value="value">Apple</option>
</select>