2016-11-16 71 views
0

我在我的Symfony2项目中使用KnpPaginatorBundle。每次我请求结果的某些页面,结果被返回到我的样子:KnpPaginatorBundle以整数形式返回currentPageNumber

{ 
    "currentPageNumber": "2", 
    "numItemsPerPage": 5, 
    "items": [ ... 
    ] 
} 

正如你可以看到currentPageNumber是串在这里。我如何将此属性的类型更改为整数?

回答

0

您可以使用standarttype在PHP铸造(documentation

对于样品,你可以做这样的:

$intValue = (int) "123"; 

而且看这种情况下:

$stringValue = "123"; 
echo gettype($stringValue); // will be 'string' here 

$intFromStringValue = (int) $stringValue; 
echo gettype($intFromStringValue); // will be 'integer' here 

// but be aware of this 
echo (int) "Some words"; // will be integer but value will be 0, because type casting cannot get the number from string 
echo (int) "200 and some words"; // integer 200 
echo (int) "Some words and 300"; // integer 0