Created
June 27, 2017 06:27
-
-
Save anonymous/1639da178f9e578ab16081154c7570a8 to your computer and use it in GitHub Desktop.
serialize json view cakephp3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protected function _dataToSerialize($serialize = true) | |
{ | |
if ($serialize === true) { | |
$data = array_diff_key( | |
$this->viewVars, | |
array_flip($this->_specialVars) | |
); | |
if (empty($data)) { | |
return null; | |
} | |
return $data; | |
} | |
if (is_array($serialize)) { | |
//added | |
$j = 1; | |
$data = []; | |
foreach ($serialize as $alias => $key) { | |
if (is_numeric($alias)) { | |
$alias = $key; | |
} | |
if (array_key_exists($key, $this->viewVars)) { | |
$data[$alias] = $this->viewVars[$key]; | |
//added | |
$data[$alias][$key]['recid'] = $j++; | |
} | |
} | |
return !empty($data) ? $data : null; | |
} | |
return isset($this->viewVars[$serialize]) ? $this->viewVars[$serialize] : null; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment