drhe80011 2015-02-06 14:07
浏览 53

为什么我需要使用substr php函数来转义:Slim index.php route参数中的冒号

My slim route (index.php) only return data to angular (app.js) when i escape parameter colon (:id) using php function substr($id,1).

When i comment the substr function the return is false because the colon before parameter id.

Why this?

app.js (angular)

var app = angular.module('app',['ngRoute']);

app.config(['$routeProvider',function($routeProvider) {
    $routeProvider.
    when('/',{controller: 'ListCtrl',templateUrl:'partials/list.html'}).
    when('/product/:param',{controller:'ListIdCtrl',templateUrl:'partials/list.html'}).
    otherwise({redirectTo:'/'});    
}]);



app.controller('ListIdCtrl',['$scope','$http','$routeParams', function($scope,$http,$routeParams){

    var requestId = $routeParams.param;
    console.log(requestId);
    $http.get("../product/" + requestId).success(function(data) {
        console.log(data); //return false


    }).
    error(function(){
        console.log('Error on get json');
    });


}]);

index.php (slim)

require 'lib/Slim/Slim.php';     //include the framework in the project
\Slim\Slim::registerAutoloader();       //register the autoloader  

$app = new \Slim\Slim(array());

$app->get('/product/:id','getProduct');

$app->run();

function getProduct($id) {
    $sql = "select * from wines where id =:id";
    try {
    $db = getConnection();
    $stmt = $db->prepare($sql);
    $id = substr($id, 1);   //need to use substr to remove colon on :id
        $stmt->bindParam(":id", $id, PDO::PARAM_INT);
        $stmt->execute();
        $wine = $stmt->fetchObject();
        $db = null;
        echo json_encode($wine);
    } catch(PDOException $e) {
        echo '{"error":{"text":'. $e->getMessage() .'}}';
    }
}


function getConnection() {
    return $dbh;
}
  • 写回答

1条回答 默认 最新

  • duandongji2231 2015-02-21 23:14
    关注

    I found the problem on html href:

    before

    <a class="text-link" href="#/product/:{{vinho.id}}" ><h4>{{vinho.username}}</h4></a>
    

    after i use ng-href withou colon

    <a class="text-link" ng-href="#/product/{{vinho.id}}" ><h4>{{vinho.username}}</h4></a>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 shape_predictor_68_face_landmarks.dat
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料