Mounting an Array CAKEPHP

1

Well, I need some help to set up an array of bad here. I got a ready calendar (bootstrap calendar) and am trying to implement it on my site with Cakephp. All right with the layout but at the time of searching the information in the database he expects to receive an Array as follows:

{"success":1,"result":[{"0":"1","id":"1","1":"Teste","title":"Teste","2":"Apenas para Teste","body":"Apenas para Teste","3":".\/descripcion_evento.php?id=1","url":".\/descripcion_evento.php?id=1","4":"event-important","class":"event-important","5":"1443105000000","start":"1443105000000","6":"1443112800000","end":"1443112800000"}]}

On the original calendar it mounts as follows:

if ($conexion->query($sql)->num_rows) { 
    $datos = array(); 

    $i=0;

    $e = $conexion->query($sql); 

    while($row=$e->fetch_array())
    {
        $datos[$i] = $row;
        $i++;
    }

    echo json_encode(               
            array(                  
                "success" => 1,     
                "result" => $datos  
            )                      
        );
}

But there is no Christ that I can do this for cakephp. the best result I had was this:

{"success":1,"result":[{"Agenda":{"id":"1","title":"teste","body":"teste","url":"teste","class":"event-important","start":"1443105000000","end":"1443112800000","0":"1","1":"teste","2":"teste","3":"teste","4":"event-important","5":"1443105000000","6":"1443112800000"}}]}

My controller looks like this:

public function obter_eventos(){
    $datos = $this->Agenda->find('all');

    foreach ($datos as $key => $dato) {
        foreach ($dato as $value) {
            $i = 0;
            foreach ($value as $valor) {
                $datos[$key]['Agenda'][$i] = $valor;
                $i++;
            }
        }
    }

    echo json_encode(              
        array(                  
            "success" => 1,     
            "result" => $datos  
        )                       
    );

    $this->autoRender=false;
}

Thanks for the help.

    
asked by anonymous 23.09.2015 / 18:35

1 answer

1

Just to stay registered and Thank Kadu, this was the solution to this problem.

public function obter_eventos(){
    $datos = $this->Agenda->find('all');

    foreach ($datos as $key => $dato) {
        foreach ($dato as $value) {
            $i = 0;
            foreach ($value as $putoti => $valor) {
                $dados[$key][$i] = $valor;
                $dados[$key][$putoti] = $valor;
                $i++;
            }
        }
    }
    echo json_encode(              
        array(                  
            "success" => 1,     
            "result" => $dados
        )                       
    );

    $this->autoRender=false;
    
23.09.2015 / 21:27