thruster/view-bundle 问题修复 & 功能扩展

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

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

thruster/view-bundle

Composer 安装命令:

composer require thruster/view-bundle

包简介

Thruster ViewBundle Bundle

README 文档

README

Latest Version Software License Build Status Code Coverage Quality Score Total Downloads

The Thruster ViewBundle Bundle. A simple addition to Symfony to provide ability to define views for simple data mappings similar to Elixir Phoenix Views.

Install

Via Composer

$ composer require thruster/view-bundle

Enable Bundle

<?php
// app/AppKernel.php

public function registerBundles()
{
    $bundles = array(
        // ...
        new Thruster\Bundle\ViewBundle(),
        // ...
    );
}

Usage

Views works similary to Symfony Controllers, all view classes should resident in Bundle/View/ folder. Some real life examples

View

<?php
// src/AppBundle/View/DefaultView.php

namespace AppBundle\View;

use Thruster\Bundle\ViewsBundle\View\View;
use AppBundle\Entity\User;

class DefaultView extends View
{
    public function welcome($name)
    {
        return [
            'msg' => 'Hello, ' . $name
        ];
    }
    
    public function me(User $user)
    {
    	  return [
    	    'name' => $user->getName(),
    	    'email' => $user->getEmail()
    	  ];
   	 }
   	 
   	 public function friend(User $friend)
   	 {
   	 	  $friend = $this->renderOne([$this, 'me'], $friend);
   	 	  // Also possible just $this->me($friend);
   	 	  
   	 	  unset($friend['email']);
   	 	  
   	 	  $friend['items'] = $this->renderMany('AppBundle:Item:public_view', $friend->getItems());
   	 	  
   	 	  return $friend;
   	 }
   	 
   	 public function friends(array $friends)
   	 {
   	 	  return [
   	 	      'data' => $this->renderMany([$this, 'friend'], $friends)
   	 	  ];
   	 }
}

Controller

<?php

namespace AppBundle\Controller;

use Thruster\Bundle\ViewsBundle\Controller\Controller;

class DefaultController extends Controller
{
    public function indexAction()
    {
        return $this->jsonView('welcome', 'guest');
    }
    
    public function meAction()
    {
    	return $this->jsonView('AppBundle:Default:me', $this->getUser());
    }
    
    public function friendAction($id)
    {
    	$friend = $this->getRepository('AppBundle:User')->find($id);
    	
    	$data = $this->view('AppBundle\View\DefaultView::friend', $friend);
    	
    	return new JsonReponse($data);
    }
    
    public function friendsAction()
    {
    	$friends = $this->getRepository('AppBundle:User')->findAll();
    	
    	return $this->jsonView('friends', $friends);
    }    
}

Testing

$ composer test

Contributing

Please see CONTRIBUTING and CONDUCT for details.

License

Please see License File for more information.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-07-05

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固