定制 yavin/symfony-init-controller 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

yavin/symfony-init-controller

Composer 安装命令:

composer require yavin/symfony-init-controller

包简介

Runs init controller method before every action

README 文档

README

Build Status

Add ability to execute init method in controller before every action. Based on this answer

Example

class SampleController extends Controller implements InitControllerInterface
{
    protected $page;

    public function init(Request $request)
    {
        if ($request->get('redirect') == 1) {
            return $this->redirect('http://example.com');
        }

       $this->page = $request->get('page');
    }

    public function indexAction()
    {
        //some action code
    }
}

Instalation

  1. Add library to composer.json

    "yavin/symfony-init-controller": "0.3"

    and run command

    composer update yavin/symfony-init-controller
    
  2. Add service in your bundle services file Resources/config/services.xml:

    <service class="Yavin\Symfony\Controller\InitControllerSubscriber">
        <tag name="kernel.event_subscriber"/>
    </service>

    or if you have services.yml:

    services:
        symfony.controller.subscriber.init:
            class: Yavin\Symfony\Controller\InitControllerSubscriber
            tags:
                - { name: kernel.event_subscriber }
  3. Then implement InitControllerInterface in controller that you want to have init method.

    namespace Acme\DemoBundle\Controller;
    
    use Symfony\Bundle\FrameworkBundle\Controller\Controller;
    use Symfony\Component\HttpFoundation\Request;
    use Yavin\Symfony\Controller\InitControllerInterface;
    
    class SampleController extends Controller implements InitControllerInterface
    {
        protected $page;
    
        public function init(Request $request)
        {
            //init method could return response, for example redirect
            if ($request->get('redirect') == 1) {
                return $this->redirect('http://example.com');
            }
    
            $this->page = $request->get('page');
        }
    
        public function indexAction()
        {
            //...
        }
    
        public function otherAction()
        {
            //...
        }
    }

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2013-12-20

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固