sfDoctrineChoiceChainPlugin - 1.0.5.2

symfony choice chain plugin

You are currently browsing
the website for symfony 1

Visit the Symfony2 website


« Back to the Plugins Home

Signin


Forgot your password?
Create an account

Tools

Stats

advanced search
Information Readme Releases Changelog Contribute
Show source

sfDoctrineChoiceChainPlugin plugin (for symfony 1.3)

The sfDoctrineChoiceChainPlugin is a symfony plugin that provides the ability to create a chain of dependant select elements that regenerate their options list depending on your choice

It gives you sfWidgetFormDoctrineChoiceChain widget plus the corresponding sfValidatorChoiceChain validator plus module to handle XHR requests

Installation

  • Install the plugin (via a package)

    symfony plugin:install sfDoctrineChoiceChainPlugin
    
  • Publish plugin assets

    symfony plugin:publish-assets
    
  • Enable the plugin module

    all:
      .settings:
        enabled_modules:      [default, sfChoiceChain]
    
  • Clear your cache

    symfony cc
    

Usage

  • Suppose you have the following schema:

    Country:
      columns:
        name: {type: string(255), notnull: true}
    
    Region:
      columns:
        country_id: {type: integer, notnull: true}
        name: {type: string(255), notnull: true}
      relations:
        Country: {local: country_id, foreign: id, onDelete: CASCADE, foreignAlias: Regions}
    
    City:
      columns:
        region_id: {type: integer, notnull: true}
        name: {type: string(255), notnull: true}
        is_capital: {type: boolean, default: false}
      relations:
        Region: {local: region_id, foreign: id, onDelete: CASCADE, foreignAlias: Cities}
    
    
    Location:
      columns:
        name: {type: string(255), notnull: true}
        country_id: {type: integer}
        region_id: {type: integer}
        city_id: {type: integer}
        #here goes more fields
      relations:
        Country: {local: country_id, foreign: id, onDelete: CASCADE, foreignAlias: Locations}
        Region: {local: region_id, foreign: id, onDelete: CASCADE, foreignAlias: Locations}
        City: {local: city_id, foreign: id, onDelete: CASCADE, foreignAlias: Locations}
    

You want your visitors to create new locations and you want them to choose first country, then load the country regions and then the cities

  • In your form

      $this->widgetSchema['location'] = new sfWidgetFormDoctrineChoiceChain(array(
             'chain' => array('Country', 'Region', 'City')
      ));
    
      $this->validatorSchema['location'] = new sfValidatorChoiceChain(array(
            'chain' => array('Country', 'Region', 'City')
      ));
    

This will give you 3 select elements, changing the values of each you will get the next refilled with new values