Created
November 24, 2013 11:19
-
-
Save kinncj/7626094 to your computer and use it in GitHub Desktop.
https://www.facebook.com/groups/nao.tem.biscoito/
"Tiago Oliveira Farias:
PHP Object to Json Without Namespace: Tenho um classe "Cliente" dentro de um namespace: "Model", ao converter para "array" (pois preciso enviar retornar via json) os índice do array são formados pelo nome da namespace junto com nome da classe e o nome da propriedade, algo …
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
<?php | |
namespace Model; | |
use PHPFluent\JSONSerializer\Serializer; | |
class Cliente extends Serializer | |
{ | |
/** | |
* @PHPFluent\JSONSerializer\Attribute | |
*/ | |
private $nome; | |
/** | |
* @PHPFluent\JSONSerializer\Attribute | |
*/ | |
private $idade; | |
public function __Construct() | |
{ | |
} | |
public function getNome() | |
{ | |
return $this->nome; | |
} | |
public function getIdade() | |
{ | |
return $this->idade; | |
} | |
public function setNome($nome) | |
{ | |
$this->nome = $nome; | |
} | |
public function setIdade($idade) | |
{ | |
$this->idade = $idade; | |
} | |
} |
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
<?php | |
require_once 'vendor/autoload.php'; | |
$cliente = new Cliente(); | |
$cliente->setNome( 'Tiago' ); | |
$cliente->setIdade( 30 ); | |
echo json_encode( $cliente ); |
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
{"nome":"Tiago","idade":30} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment