zent/vars-bundle

Symfony2 扩展动态参数

安装次数: 609

依赖者: 0

建议者: 0

安全性: 0

星标: 0

关注者: 2

分支: 0

开放问题: 0

类型:symfony-bundle

v0.2 2017-07-16 21:30 UTC

This package is auto-updated.

Last update: 2024-09-27 10:25:14 UTC


README

SensioLabsInsight

步骤 1: 使用 composer 下载 ZentVarsBundle

composer require zent/vars-bundle dev-master

步骤 2: 启用扩展

在内核中启用扩展

<?php
// app/AppKernel.php

public function registerBundles()
{
    $bundles = array(
        // ...
        new Zent\VarsBundle\ZentVarsBundle(),
        // ...
    );
}
步骤 3: 创建你的 Vars 类
// src/AppBundle/Entity/Vars.php
use Zent\VarsBundle\Entity\BaseVars;

class Vars extended BaseVars
{
}
步骤 4: 配置 ZentVarsBundle
# app/config/config.yml
zent_vars:
    class: AppBunde\Entity\Vars

如果需要额外的缓存

doctrine_cache:
    providers:
        zent_vars_query_cache:
            type: apc
            namespace: query_cache_ns
            alias:
              - zent_vars.cache

文档: https://symfony.com.cn/doc/current/bundles/DoctrineCacheBundle/reference.html

步骤 5: 更新数据库模式

使用方法

访问用户管理服务
$varsManager = $container->get('zent_vars.manager');
$var = $varsManager->getValue('first');
$var = $varsManager->getValue('first', 10); //return '10' if var not found 
Twig
{{ vars('first') }}

命令行工具

php app/console zent:vars:create email_owner test@example.com "Email владельца"
php app/console zent:vars:update email_owner test@test.com
php app/console zent:vars:delete email_owner
php app/console zent:vars:list