douxieti6851 2018-03-21 17:52
浏览 83

将php多维数组反序列化为angularjs

I'm trying to deserialize a multi array from php and after pass it to angular.js This is what i got:

libray.php

public function Read()
{
    $query = $this->db->prepare("select idMensaje, Titulo, DATE_FORMAT(FInicioPub, '%d/%m/%Y') as Inicia, DATE_FORMAT(FFinPub, '%d/%m/%Y') as Termina, Hora, Lugar, Observacion FROM EventosRegion where IdRegion = 1 order by FInicioPub");
    $query->execute();
    $data = array();
    while ($row = $query->fetch(PDO::FETCH_ASSOC)) {
        $data[] = $row;
    }
    // This is just for test => var_dump($data);
    return json_encode(['events' => $data]);
}

After this i have a file called: list.php:

require_once ('library.php');
$event = new Event();
$result = $event->Read();
echo  json_encode(['events' => $result]);

And in my js file events.js have this:

// List of events
$scope.events = [];
$scope.listEvents = function () {
    $http.get('/actions/forms/event/list.php', {})
        .then(function success(e) {
            $scope.events = e.data;
            // just trying to see results here 
            console.log("Parsed object" + JSON.parse(e));
            console.log("The events: " + JSON.stringify(e.data));
        }, function error(e) {
            console.log("There's an error: " + e);
        });
};
$scope.listEvents();

And the result of this is this:

    array(5) { 
  [0]=> array(7) { ["idMensaje"]=> int(1) ["Titulo"]=> string(14) "Junta regional" ["Inicia"]=> string(10) "12/04/2014" 

["Termina"]=> string(10) "13/04/2014" ["Hora"]=> string(8) "15:00:00" ["Lugar"]=> string(46) "Grupo nuevo amanecer. Puerto Vallarta, Jalisco" ["Observacion"]=> string(94) "Al dia siguiente de la junta regional se realizará un convivio y el clásico partido de futbol." } 
  [1]=> array(7) { ["idMensaje"]=> int(3) ["Titulo"]=> string(14) "Junta regional" ["Inicia"]=> string(10) "28/06/2014" ["Termina"]=> string(10) "28/06/2014" ["Hora"]=> string(8) "15:00:00" ["Lugar"]=> string(38) "Grupo Bievenidos, Guadalajara, Jalisco" ["Observacion"]=> string(25) "Favor de llegar puntuales" } 
  [2]=> array(7) { ["idMensaje"]=> int(2) ["Titulo"]=> string(11) "CROMEX XIII" ["Inicia"]=> string(10) "31/07/2014" ["Termina"]=> string(10) "03/08/2014" ["Hora"]=> string(8) "12:00:00" ["Lugar"]=> string(60) "Hotel Diana del Bosque. Morelia Michoacán
Lada sin costo" ["Observacion"]=> string(183) "Para más información comunicarse con Julio:
Celular: 4525457491
Nextel: 72*15*57254
Página del hotel " } 
  [3]=> array(7) { ["idMensaje"]=> int(5) ["Titulo"]=> string(14) "Junta regional" ["Inicia"]=> string(10) "18/04/2015" ["Termina"]=> string(10) "18/04/2015" ["Hora"]=> string(8) "15:00:00" ["Lugar"]=> string(18) "Las Varas, Nayarit" ["Observacion"]=> string(20) "Asiste puntualmente." } 
  [4]=> array(7) { ["idMensaje"]=> int(4) ["Titulo"]=> string(10) "CROMEX XIV" ["Inicia"]=> string(10) "31/07/2015" ["Termina"]=> string(10) "02/08/2015" ["Hora"]=> string(8) "12:00:00" ["Lugar"]=> string(20) "Guadalajara, Jalisco" ["Observacion"]=> string(156) "Asiste a nuestra próxima convención en Guadalajara, Jalisco.
Hotel sede: Plaza Diana    
" } } 

And in my view index.php i got this:

<tr ng-repeat="event in events">
                        <td>{{ event.idMensaje }}</td>
                        <td>{{ event.Titulo }}</td>
                        <td>{{ event.Inicia }}</td>
                        <td>{{ event.Termina }}</td>
                        <td>{{ event.Lugar }}</td>
                        <td>
                            <button ng-click="edit(event)"  class="btn btn-primary btn-md">Edit</button>
                            <button ng-click="delete(event)" class="btn btn-danger btn-md">Delete</button>
                        </td>
                    </tr>

And i receive this error:
Notice: Array to string conversion in /home/yoursite/public_html/actions/forms/event/library.php on line 65
Array{\"events\":false}

json_encode() 

Is SUPOSSED to do what i'm expecting, but is not working. At least with type of arrays.

And i know that a "Notice" is NOT an error as such, is just an advisory message meaning something like: "you are not doing things well". I can't show data on my view, but i can see the results of my query. Any help/solutions?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥50 树莓派安卓APK系统签名
    • ¥15 maple软件,用solve求反函数出现rootof,怎么办?
    • ¥65 汇编语言除法溢出问题
    • ¥15 Visual Studio问题
    • ¥15 state显示变量是字符串形式,但是仍然红色,无法引用,并显示类型不匹配
    • ¥20 求一个html代码,有偿
    • ¥100 关于使用MATLAB中copularnd函数的问题
    • ¥20 在虚拟机的pycharm上
    • ¥15 jupyterthemes 设置完毕后没有效果
    • ¥15 matlab图像高斯低通滤波