class Controller_API extends Controller_Rest {
public function get_list()
{
$users = Model_User::find('all');
//print_r($users)
$this->response($users);
}
}
This will output:
{
1: { }
2: { }
}
I have two users in my test environment, so having 2 json values would be correct, but they're empty. $users = Model_User::find('all', array('related' => array('votes')));
//print_r($users);
$users = Format::factory($users)->to_array();
$this->response($users);
This will output $users correctly, but without votes.
$model = Model_Example::find(1); $array = $model->to_array();
response($data = array(), $http_code = 200)
foreach($users as $user) { // Build your array here before sending it on }Phil.
$u_response = array(); foreach ($users as $user) { $my_user['name'] = $user->name; $my_user['nickname'] = $user->nickname; array_push($u_response,$my_user); }
public function get_list()
{
$users = Model_User::find('all');
echo json_encode($users);
}
foreach ((array) $data as $key => $value)
foreach ($data as $key => $value)
$blogs = Model_Blog::find('all');
$blogs = Format::factory($blogs)->to_array();
$this->response($blogs);
class ClassToSerialize implements JsonSerializable
{
private $foo = 42; // <-- normaly not serializable
private $bar = 23; // <-- normaly not serializable
public function JsonSerialize() {
return array(
'foo' => $this->foo,
'bar' => $this->bar
);
}
}
$json = json_encode(new ClassToSerialize()) // output => {"foo":42, "bar": 23}
It looks like you're new here. If you want to get involved, click one of these buttons!