maesbox / common-bundle
通用功能包
1.1.0
2017-01-25 14:16 UTC
Requires
- php: >=5.3.9
- doctrine/doctrine-bundle: ~1.4
- doctrine/orm: >=2.4
- guzzlehttp/guzzle: >=5.0
- jms/security-extra-bundle: >=1.0
- jms/serializer-bundle: >=1.0
- knplabs/knp-paginator-bundle: ^2.0
- stof/doctrine-extensions-bundle: >=1.0
- symfony/symfony: >=2.8
This package is auto-updated.
Last update: 2024-09-17 09:48:41 UTC
README
安装
composer
composer require maesbox/commonbundle
kernel
将这些行添加到app/AppKernel.php
<?php
use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\Config\Loader\LoaderInterface;
class AppKernel extends Kernel
{
public function registerBundles()
{
$bundles = array(
//...
new Sonata\SeoBundle\SonataSeoBundle(),
new Symfony\Cmf\Bundle\SeoBundle\CmfSeoBundle(),
new JMS\SerializerBundle\JMSSerializerBundle(),
new JMS\AopBundle\JMSAopBundle(),
new JMS\SecurityExtraBundle\JMSSecurityExtraBundle(),
new Knp\Bundle\PaginatorBundle\KnpPaginatorBundle(),
new Stof\DoctrineExtensionsBundle\StofDoctrineExtensionsBundle(),
//...
new Maesbox\CommonBundle\MaesboxCommonBundle(),
//...
);
}
//...
}
配置
MaesboxCommonBundle
doctrine:
orm:
entity_managers:
default:
dql:
datetime_functions:
#date: YourApp\YourBundle\DQL\Date
#hour: YourApp\YourBundle\DQL\Hour
month: Maesbox\CommonBundle\Model\DQL\Month
year: Maesbox\CommonBundle\Model\DQL\Year
StofDoctrineExtensionsBundle
doctrine:
orm:
entity_managers:
default:
mappings:
gedmo_translatable:
type: annotation
prefix: Gedmo\Translatable\Entity
dir: "%kernel.root_dir%/../vendor/gedmo/doctrine-extensions/lib/Gedmo/Translatable/Entity"
alias: GedmoTranslatable
is_bundle: false
gedmo_translator:
type: annotation
prefix: Gedmo\Translator\Entity
dir: "%kernel.root_dir%/../vendor/gedmo/doctrine-extensions/lib/Gedmo/Translator/Entity"
alias: GedmoTranslator
is_bundle: false
gedmo_loggable:
type: annotation
prefix: Gedmo\Loggable\Entity
dir: "%kernel.root_dir%/../vendor/gedmo/doctrine-extensions/lib/Gedmo/Loggable/Entity"
alias: GedmoLoggable
is_bundle: false
gedmo_tree:
type: annotation
prefix: Gedmo\Tree\Entity
dir: "%kernel.root_dir%/../vendor/gedmo/doctrine-extensions/lib/Gedmo/Tree/Entity"
alias: GedmoTree
is_bundle: false
对于更高级的选项,请参阅包文档
功能
控制器
<?php
use Maesbox\CommonBundle\Model\BaseClass\BaseController;
class AppController extends BaseController
{
}
提供多种方法
- getSession
- getSerializer
- getParameter
- getEventDispatcher
- getManager
- getBaseManager
- getRepository
- getSecurity
- getCurrentUser
- getTranslator
实体管理器
- 首先,你的管理器必须扩展
Maesbox\CommonBundle\Model\BaseClass\BaseManager
<?php
use Maesbox\CommonBundle\Model\BaseClass\BaseManager;
class AppManager extends BaseManager
{
}
- 其次,你必须注释你想公开的存储库方法
<?php
use Doctrine\ORM\EntityRepository;
use Maesbox\CommonBundle\Model\Annotation\SingleResultQuery;
use Maesbox\CommonBundle\Model\Annotation\SingleScalarResultQuery;
use Maesbox\CommonBundle\Model\Annotation\ListResultQuery;
use Maesbox\CommonBundle\Model\Annotation\ListScalarResultQuery;
class AppRepository extends EntityRepository
{
/**
* @SingleResultQuery
*/
public function getSingleResultQuery($params){
return $this->createQueryBuilder("a");
}
/**
* @SingleScalarResultQuery
*/
public function getSingleScalarResultQuery($params){
return $this->createQueryBuilder("a");
}
/**
* @ListResultQuery
*/
public function getListResultQuery($params){
return $this->createQueryBuilder("a");
}
/**
* @ScalarListResultQuery
*/
public function getScalarListResultQuery($params){
return $this->createQueryBuilder("a");
}
}
监听器
控制台监听器
记录控制台错误:)