gonzakpo/comun

Comun Bundle 提供了针对使用 Symfony 进行开发的常见情况下的解决方案

安装次数: 1,156

依赖者: 0

建议者: 0

安全: 0

星标: 2

关注者: 3

分支: 1

开放性问题: 0

类型:symfony-bundle

v3.0.5 2017-03-23 14:14 UTC

This package is auto-updated.

Last update: 2024-09-10 11:33:08 UTC


README

Comun Bundle 提供了针对使用 Symfony 进行开发的常见情况下的解决方案

Composer

php composer.phar require gonzakpo/comun

AppKernel

new Tecspro\Bundle\ComunBundle\TecsproComunBundle(),

如何使用 bundle 的服务?

bundle 中的每个服务都有一个单独的 .yml 文件用于使用该服务。只需在系统的 config.yml 中导入所需服务的 .yml 文件即可。

services:
    tecspro_comun.slugify:
        class: Tecspro\Bundle\ComunBundle\Services\Slugify
    tecspro_comun.helpers_object_relation:
        class: Tecspro\Bundle\ComunBundle\Services\HelpersObjectRelation
    tecspro_comun.comun_mailer:
        class: Tecspro\Bundle\ComunBundle\Services\ComunMailer

例如:

service_helpers_object_relation: 返回数组之间的元素差异,以及两个数组之间的公共元素。

$helpersObjectRelation = $this->get('tecspro_comun.helpers_object_relation');

$originalEntities = $entity->getEntities()->getValues();
$form->handleRequest($request);
$newEntities = $entity->getEntities()->getValues();

$entitiesAdd = $helpersObjectRelation->getEntitiesToAdd($newEntities, $originalEntities);

$entitiesRemove = $helpersObjectRelation->getEntitiesToRemove($newEntities, $originalEntities);

service_slugify: 过滤字符串中的特殊字符,如重音符号或符号。

service_mailer: 使用 mailer 服务发送电子邮件的服务。必须

$services_comunmailer = $this->get('tecspro_comun.comun_mailer');

$services_comunmailer->send_mailer($asunto, $remitente, $destinatarios, $mensaje);

JavaScript 函数

在表单输入中控制模式

在视图中包含

<script src="{{ asset('bundles/tecsprocomun/js/controla_patron.js') }}"></script>

在表单的 type 中包含(以下示例只允许数字)

选项 1

->add('campo', null, array(
    'attr'  => array(
        ...
        'class' => 'mwsValidaPatron',
        'mwspatron' => '[0-9]',
    )
))

选项 2

->add('campo', null, array(
    'attr'  => array(
        ...
        'onkeypress' => 'return validaPatron(event, "[0-9]")',
    )
))

替换字符

在视图中包含

<script src="{{ asset('bundles/tecsprocomun/js/reemplaza_valor.js') }}"></script>

在表单的 type 中包含(此示例将 . 替换为 ,)

->add('campo', null, array(
    'attr'  => array(
        ...
        'class' => 'mwsReemplazaValor',
        'mwsreemplazar'    => '.',
        'mwsreemplazarpor' => ',',
    )
))

作者

Gonzalo Alonso - gonkpo@gmail.com

协作者

中文 - emmanuel_cabral@hotmail.com