小编ker*_*zen的帖子

使用symfony 2序列化器对对象中的嵌套结构进行非规范化

我正在使用版本2.8的Symfony 2项目,我正在使用内置组件Serializer - > http://symfony.com/doc/current/components/serializer.html

我有一个由Web服务提供的JSON结构.反序列化后,我想在对象中反规范化我的内容.这是我的结构(汽车应用程序上下文中的模型/品牌).

[{
"0": {
    "id": 0,
    "code": 1,
    "model": "modelA",
    "make": {
        "id": 0,
        "code": 1,
        "name": "makeA"
    }
  }
} , {
 "1": {
    "id": 1,
    "code": 2,
    "model": "modelB",
    "make": {
        "id": 0,
        "code": 1,
        "name": "makeA"
    }
  }
}]
Run Code Online (Sandbox Code Playgroud)

我的想法是填充一个VehicleModel包含对象引用的VehicleMake对象.

class VehicleModel {
    public $id;
    public $code;
    public $model;
    public $make; // VehicleMake
}
Run Code Online (Sandbox Code Playgroud)

这是我做的:

// Retrieve data in JSON
$data = ...
$serializer = new Serializer([new ObjectNormalizer(), …
Run Code Online (Sandbox Code Playgroud)

php json denormalization symfony

13
推荐指数
1
解决办法
8830
查看次数

使用composer安装phpdocumentor/reflection

我想在我的SF2项目中安装包phpdocumentor/reflexion.所以我运行以下命令,composer require "phpdocumentor/reflection"但我有以下堆栈错误:

 Your requirements could not be resolved to an installable set of packages.

Problem 1

- Conclusion: don't install phpdocumentor/reflection 3.0.1
- Conclusion: remove phpdocumentor/reflection-docblock 3.1.1
- Installation request for phpdocumentor/reflection ^3.0 -> satisfiable by phpdocumentor/reflection[3.0.0, 3.0.1].                                                                                                ?  Feature/T4136-18-identification-by-vin
- Conclusion: don't install phpdocumentor/reflection-docblock 3.1.1
- phpdocumentor/reflection 3.0.0 requires phpdocumentor/reflection-docblock ~2.0 -> satisfiable by phpdocumentor/reflection-docblock[2.0.0, 2.0.0a1, 2.0.0a2, 2.0.0a3, 2.0.1, 2.0.2, 2.0.3, 2.0.4].               ?  master
- Can only install one of: phpdocumentor/reflection-docblock[2.0.0, 3.1.1].
- Can only install …
Run Code Online (Sandbox Code Playgroud)

php composer-php phpdocumentor2

1
推荐指数
1
解决办法
1469
查看次数

在 Drupal 8 块表单中添加字段链接

我想link在自定义块中有一个字段。这是我的代码:

public function blockForm($form, FormStateInterface $form_state)
{

    $form['key_1'] = [
        '#title' => $this->t('Key 1 label'),
        '#type' => 'textfield',
        '#default_value' => '',
        '#required' => false,
    ];

    $form['key_2'] = [
        '#title' => $this->t('key 2 link'),
        '#type' => 'link',
    ];

    return $form;
}
Run Code Online (Sandbox Code Playgroud)

现在,当我进入 admin/structure/block/manage/myblock 时,我可以看到我的key 1字段。在key 2不渲染。如果我更改任何其他(文本字段、文本区域、文件管理)的类型,我的字段将正确呈现。默认链接模块已启用。

链接字段类型只能在节点形式中使用吗?我能理解为什么。

drupal-8

0
推荐指数
1
解决办法
4713
查看次数