php - Create a blank array from a model in cakephp -


hi,

i have working model , want able create array key names , have them empty.

to illustrate, model client comes clients table, , example when this:

$this->client->find( 'first' );

i following array (json encoded):

{     client: {         id: "39",         name: "andrux",         phone: "1234567890",         email: "me@andrux.com",         city_id: "2"     },     city: {         id: "2",         city_name: "andruxville"     } } 

as can see, set model have relationship city model, both client , city arrays result of find method.

now need same array without values, , can't find answer this, have tried solutions none have worked way want, example tried using array_map function , schema method of model gives me column names of clients table, can set null if want city model?

the end result want following:

{     client: {         id: "",         name: "",         phone: "",         email: "",         city_id: ""     },     city: {         id: "",         city_name: ""     } } 

anyone knows how accomplish this? rather find way of doing cakephp way - if there 1 - solution gets me desired result appreciated.

thanks guys!

well, if ok, create custom function in model , pass in result it, like:

//can added model function reset_values($array, $replace_with) {     foreach ($array $key => $arr) {     if(is_array($arr)) $res[$key] = reset_values($arr,$replace_with);     else $res[$key] = $replace_with;     }     return $res; } $resetedarr = reset_values($arr, null); //replace values null echo "<pre>"; print_r($resetedarr); 

Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -