ibrows/wizard-annotation-bundle

带有验证方法的控制器简单向导

安装数: 8,369

依赖者: 1

建议者: 0

安全: 0

星标: 0

关注者: 1

分支: 0

开放问题: 0

类型:symfony-bundle

1.3.0 2016-04-12 16:26 UTC

This package is auto-updated.

Last update: 2024-09-15 19:01:16 UTC


README

为Symfony2控制器提供一个简单的带有注解的向导/工作流程。

如何安装

将Bundle添加到你的composer.json文件中

// composer.json

{
    "require": {
        "ibrows/wizard-annotation-bundle": "*"
    }
}

使用composer.phar从控制台安装Bundle

$ php composer.phar update ibrows/wizard-annotation-bundle

在AppKernel.php中启用Bundle

<?php
// app/AppKernel.php

public function registerBundles()
{
    $bundles = array(
        // ...
        new Ibrows\Bundle\WizardAnnotationBundle\IbrowsWizardAnnotationBundle(),
    );
}

在控制器中使用

<?php

namespace YourApp\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\RedirectResponse;

use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;

use Ibrows\Bundle\WizardAnnotationBundle\Annotation\Wizard;

/**
 * @Route("/wizard")
 */
class WizardController extends Controller
{
    /**
     * @Route("/register", name="wizard_register")
     * @Template
     * @Wizard(name="register", number=1)
     * @return array
     */
    public function registerAction()
    {
        return array();
    }

    /**
     * @Route("/address", name="wizard_address")
     * @Template
     * @Wizard(name="address", number=2, validationMethod="addressValidation")
     * @return array
     */
    public function addressAction()
    {
        return array();
    }

    /**
     * @return bool
     */
    public function addressValidation()
    {
        /**
         * Do your checks if this step is valid and return a Response/RedirectResponse or Wizard::REDIRECT_STEP_BACK
         * if something is wrong. Otherwise return true
         */

        if(!$this->getUser()){
            return Wizard::REDIRECT_STEP_BACK;
        }

        return true;
    }

    /**
     * @Route("/summary", name="wizard_summary")
     * @Template
     * @Wizard(name="summary", number=3, validationMethod="summaryValidation")
     * @return array
     */
    public function summaryAction()
    {
        return array();
    }

    /**
     * @return bool
     */
    public function summaryValidation()
    {
        /**
         * Do your checks if this step is valid and return a Response/RedirectResponse or Wizard::REDIRECT_STEP_BACK
         * if something is wrong. Otherwise return true
         */

        if(!$this->someCheck()){
            return new RedirectResponse($this->generateUrl('index'));
        }

        if(!$this->someOtherCheck()){
            return new RedirectResponse($this->generateUrl('login'));
        }

        return true;
    }

    /**
     * @Route("/display", name="wizard_display")
     * @Template
     * @return array
     */
    public function displayAction()
    {
        return array(
            'wizard' => $this->get('ibrows_wizardannotation.annotation.handler')
        );
    }
}

显示向导

只需在视图中渲染wizardAction即可

    {% render "YourBundle:Wizard:display" %}

以及diplay.html.twig

    {% extends 'IbrowsWizardAnnotationBundle:Wizard:base.html.twig' %}