kapitanluffy/propel-model-parser-bundle 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

kapitanluffy/propel-model-parser-bundle

最新稳定版本:v1.0.0

Composer 安装命令:

composer require kapitanluffy/propel-model-parser-bundle

包简介

parses propel models to json-fiable data

关键字:

README 文档

README

The PropelModelParserBundle enables Propel BaseObjects to be parsed into array, which in turn can be converted into JSON for API responses.

Unlike native BaseObject methods like toJSON(), the PropelModelParserBundle can automatically convert BaseObjects as well as their "child objects" to array, as well as add custom properties.

Installation:

  1. Install PropelModelParserBundle using Composer
  2. Register bundle in AppKernel
  3. In your Propel schema.xml, Use kapitanluffy\PropelModelParserBundle\BaseModel as your baseClass
  4. Rebuild Propel models.

Usage:

In your controller..

<?php
namespace AppBundle\Controller;

use kapitanluffy\PropelModelParserBundle\PropertyCollection;
use Symfony\Component\HttpFoundation\;

class DefaultController extends Controller
{
    public function indexAction($user_id)
    {
        $user = Model\UserQuery::create()
        ->joinWith('Post')
        ->findOneById($user_id);
        
        $post_count = $user->getPosts()->count();
        
        $properties = new PropertyCollection;
        $properties->addProperty('posts', 'getPosts')
            // parse child object's (post) children (user)
            ->useProperty('posts')
                ->addProperty('poster', 'getUser')
            ->endUse()
            // add custom property
            ->addProperty('post_count', $post_count);
        
        $data = $user->parseObject($properties);
        
        $response = new JsonResponse;
        $response->setData($data);
        return $response;
    }
}

Will result into

{
    "id":1,
    "username":"user1",
    "password":"pass",
    "email":"user1@email.com",
    "posts":[
        {
            "id":1,
            "string":"this is user1\u0027s post",
            "user_id":1,
            "created_at":{
                "date":"2015-06-24 11:28:52.000000",
                "timezone_type":3,
                "timezone":"UTC"
            },
            "updated_at":{
                "date":"2015-06-24 11:28:52.000000",
                "timezone_type":3,
                "timezone":"UTC"
            },
            "poster":{
                "id":1,
                "username":"user1",
                "password":"pass",
                "email":"user1@email.com"
            }
        },
        {
            "id":4,
            "string":"another user1 post",
            "user_id":1,
            "created_at":{
                "date":"2015-06-24 11:28:52.000000",
                "timezone_type":3,
                "timezone":"UTC"
            },
            "updated_at":{
                "date":"2015-06-24 11:28:52.000000",
                "timezone_type":3,
                "timezone":"UTC"
            },
            "poster":{
                "id":1,
                "username":"user1",
                "password":"pass",
                "email":"user1@email.com"
            }
        }
    ],
    "post_count":2
}

统计信息

  • 总下载量: 23
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-04-29

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固