PHP中有一个非常糟糕的限制:如果你调用一个调用a2()的函数a1(),那就调用a3 ...所以什么时候a99()调用a100()你会看到
致命错误:达到最大功能嵌套级别'100',正在中止!
有没有办法将100个嵌套调用的限制增加到500或10000?
这对我来说至关重要,因为我正在开发一个带有大量回调的基于事件的系统.
我正在使用jQuery编辑我在Symfony中构建的表单.
我在jQuery对话框中显示该表单,然后提交它.
数据在数据库中正确输入.
但我不知道是否需要将一些JSON发送回jQuery.其实我对JSON的事情有点困惑.
假设我在我的表中添加了一行jQuery,当我提交表单然后提交数据后,我想发回那些行数据,以便我可以动态添加表行来显示添加的数据.
我很困惑如何才能获得这些数据
这是我目前的代码
$editForm = $this->createForm(new StepsType(), $entity);
$request = $this->getRequest();
$editForm->bindRequest($request);
if ($editForm->isValid()) {
$em->persist($entity);
$em->flush();
return $this->render('::success.html.twig');
}
Run Code Online (Sandbox Code Playgroud)
这只是带有成功消息的模板
我正在使用Symfony2,Doctrine,FOSRestBundle和JMSSerializer构建REST API.
我遇到的问题是在序列化我的实体时,序列化程序会引入任何相关实体.例如,对于作为董事会一部分的故事的一部分的任务,所以在序列化任务时,我得到的输出包括包含董事会的故事,其中包括董事会上的所有其他故事.
有没有一种简单的方法来限制它,只是包含foreignIds?
想要将doctrine entiry对象转换为普通数组,这是我的代码到目前为止,
$demo = $this->doctrine->em->find('Entity\User',2);
Run Code Online (Sandbox Code Playgroud)
获取实体对象,
Entity\User Object
(
[id:Entity\User:private] => 2
[username:Entity\User:private] => TestUser
[password:Entity\User:private] => 950715f3f83e20ee154995cd5a89ac75
[email:Entity\User:private] => test@test.com
[firm_id:Entity\User:private] => Entity\Firm Object
(
[id:Entity\Firm:private] => 16
[company_name:Entity\Firm:private] => TestFirm
[company_detail:Entity\Firm:private] => India
[created_at:Entity\Firm:private] => DateTime Object
(
[date] => 2014-08-01 18:16:08
[timezone_type] => 3
[timezone] => Europe/Paris
)
[user:Entity\Firm:private] =>
)
[created_at:Entity\User:private] => DateTime Object
(
[date] => 2014-08-01 15:12:36
[timezone_type] => 3
[timezone] => Europe/Paris
)
[updated_at:Entity\User:private] => DateTime Object
(
[date] => 2014-08-01 15:12:36
[timezone_type] …Run Code Online (Sandbox Code Playgroud) 我正在使用Doctrine 1.2,我怎样才能将查询对象变成json/array格式?
$user = Doctrine_Query::create()
->select('u.id, u.username, u.firstname, u.lastname')
->from('User u')
->orderby('u.id')
->execute();
Run Code Online (Sandbox Code Playgroud) 我正在使用Symfony 2和Doctrine 2为iOS应用程序创建Web服务(JSON).
要获取我的实体我做:
$articles = $this->getDoctrine()->getRepository('UdoPaddujourBundle:MenuArticle')->findAll();
Run Code Online (Sandbox Code Playgroud)
我必须告诉你:
$article = array();
$article = $articles->toArray();
Run Code Online (Sandbox Code Playgroud)
给我以下错误:
Fatal error: Call to a member function toArray() on a non-object
Run Code Online (Sandbox Code Playgroud)
同样的事情发生了
$article = $articles->exportTo('json');
Run Code Online (Sandbox Code Playgroud)
我怎样才能创建一个json响应?
亲切的问候,Cearnau Dan
编辑:var_dump($ articles)=
array(18) {
[0]=>
object(Udo\PaddujourBundle\Entity\MenuArticle)#50 (4) {
["id":"Udo\PaddujourBundle\Entity\MenuArticle":private]=>
int(1)
["name":"Udo\PaddujourBundle\Entity\MenuArticle":private]=>
string(17) "My Article Name 1"
["description":"Udo\PaddujourBundle\Entity\MenuArticle":private]=>
string(26) "My Article Description 1"
["price":"Udo\PaddujourBundle\Entity\MenuArticle":private]=>
float(20)
}
[1]=> ...
Run Code Online (Sandbox Code Playgroud)
我怎样才能遍历所有"属性名称"?这就是我所拥有的:
$myarray=array();
$myArray["name"]=array();
$myArray["description"]=array();
foreach($articles in $article)
{
array_push($myArray["name"], $article->getName());
array_push($myArray["description"], $article->getDescription());
}
Run Code Online (Sandbox Code Playgroud) 总是我得到一个空白,我在我的控制器中有这样的动作
/**
* @Route("/check/{key}.json", defaults={"_format"="json"})
* @Template()
*/
public function processAction($upload_key)
{
/* make thing */
return array('data' => $process_data);
}
Run Code Online (Sandbox Code Playgroud)
在我的process.json.twig文件中
{% set res = { 'data': data } %}
{{ res | json_enconde | raw }}
Run Code Online (Sandbox Code Playgroud)
其他形式
{{ { 'data': data } | json_enconde | raw }}
Run Code Online (Sandbox Code Playgroud)
我也试过这个:
{{ 'hello' | json_encode | raw }}
Run Code Online (Sandbox Code Playgroud)
在铬我得到这个回应:
Connection:close
Content-Length:0
Content-Type:application/json
Date:Mon, 19 Dec 2011 05:13:17 GMT
Server:Apache/2.2.20 (Ubuntu)
X-Powered-By:PHP/5.3.6-13ubuntu3.3
Run Code Online (Sandbox Code Playgroud)
从服务器得到任何东西,我无法解决这个问题
php ×6
json ×4
symfony ×4
doctrine ×3
doctrine-orm ×2
arrays ×1
doctrine-1.2 ×1
javascript ×1
web-services ×1
xdebug ×1