Skip to content

Commit

Permalink
Merge pull request #1594 from dreamsxin/model_1506
Browse files Browse the repository at this point in the history
Fix #1506 in v1.2.5 add Model\Row::toArray
  • Loading branch information
Phalcon committed Nov 25, 2013
2 parents 82537d4 + 05717d6 commit b05126e
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
36 changes: 36 additions & 0 deletions ext/mvc/model/row.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@

#include "kernel/object.h"
#include "kernel/exception.h"
#include "kernel/array.h"

/**
* Phalcon\Mvc\Model\Row
Expand Down Expand Up @@ -141,3 +142,38 @@ PHP_METHOD(Phalcon_Mvc_Model_Row, offsetUnset){
return;
}

/**
* Returns the instance as an array representation
*
* @return array
*/
PHP_METHOD(Phalcon_Mvc_Model_Row, toArray){

zval *properties, *key = NULL, *value = NULL;
HashTable *ah0;
HashPosition hp0;
zval **hd;

PHALCON_MM_GROW();

properties = Z_OBJ_HT_P(this_ptr)->get_properties(this_ptr TSRMLS_CC);

if (properties == NULL) {
RETURN_MM_FALSE;
}

array_init(return_value);

zend_hash_internal_pointer_reset_ex(properties, &hp0);
while (zend_hash_get_current_data_ex(properties, (void**) &hd, &hp0) == SUCCESS) {
PHALCON_GET_HKEY(key, ah0, hp0);
PHALCON_GET_HVALUE(value);

phalcon_array_update_zval(&return_value, key, &value, PH_COPY | PH_SEPARATE);

zend_hash_move_forward_ex(ah0, &hp0);
}

RETURN_MM();
}

2 changes: 2 additions & 0 deletions ext/mvc/model/row.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ PHP_METHOD(Phalcon_Mvc_Model_Row, offsetExists);
PHP_METHOD(Phalcon_Mvc_Model_Row, offsetGet);
PHP_METHOD(Phalcon_Mvc_Model_Row, offsetSet);
PHP_METHOD(Phalcon_Mvc_Model_Row, offsetUnset);
PHP_METHOD(Phalcon_Mvc_Model_Row, toArray);

ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_mvc_model_row_setdirtystate, 0, 0, 1)
ZEND_ARG_INFO(0, dirtyState)
Expand Down Expand Up @@ -54,6 +55,7 @@ PHALCON_INIT_FUNCS(phalcon_mvc_model_row_method_entry){
PHP_ME(Phalcon_Mvc_Model_Row, offsetGet, arginfo_phalcon_mvc_model_row_offsetget, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Mvc_Model_Row, offsetSet, arginfo_phalcon_mvc_model_row_offsetset, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Mvc_Model_Row, offsetUnset, arginfo_phalcon_mvc_model_row_offsetunset, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Mvc_Model_Row, toArray, NULL, ZEND_ACC_PUBLIC)
PHP_FE_END
};

0 comments on commit b05126e

Please sign in to comment.