Skip to content
CakePHP plugin for Harvest's Chosen library
JavaScript PHP
Find file
Pull request Compare This branch is 5 commits ahead, 18 commits behind paulredmond:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.

ChosenHelper for CakePHP 2

ChosenHelper is a class for integrating HarvestHQ Chosen select boxes in CakePHP 2. Check out HarvestHQ's demo for documentation and usage.

Build Status


A Changelog Wiki page is now available. Review it carefully to make sure you do not upgrade permaturely. For example: the latest version (2.1.0) includes a backwards compatability break with CakePHP 2.0.x.


Chosen CakePHP 2 plugin supports Composer and Packagist. After you download composer.phar and put it in your path:

Composer will take care of installing the plugin into the correct location. Include the following composer.json file at path/to/app

    "require": {
        "paulredmond/chosen-cakephp": "*"

Use a sensible stable version for the plugin. The above '*' is only intended as an example.

cd path/to/app
php composer.phar install

Bootstrap the plugin in app/Config/bootstrap.php:


// ...



Optional webroot symlink

cd /path/to/app/webroot
ln -s ../Plugin/Chosen/webroot chosen


In /app/Controller/AppController.php:


public $helpers = array(

Out of the box, the ChosenHelper will work with jQuery; but you might want prototype or a custom class:


public $helpers = array(
    'Chosen.Chosen' => array(
        'framework' => 'prototype',
        'class'     => 'chosen-custom', // Deselect-enabled class would be 'chosen-custom-deselect'

Now all classes rendered with the helper, or other <select> inputs with your configured class will be targeted.

JQuery / Prototype

Make sure that you are loading JQuery (1.4+) or Prototype however you want:


// One way in In default.ctp
echo $this->Html->script('jquery'); // sets src to /js/jquery.js
  • Note: Chosen CSS/JS files are only loaded if the helper select method is called at least once.*

Pull Requests

Chosen CakePHP plugin has contributions from the Github communitiy. I am grateful for the suggestions, fixes, and improvements. If you'd like to submit a pull request, follow these simple instructions:

  • Pull requests for the 2.1.x version should be submitted to the 2.1 branch
  • If the supported 2.0 branch (for CakePHP 2.0.x) could benefit from your Pull Request, consider opening another Pull Request for that branch.
  • The master branch reflects the latest stable version available.


You can run tests for Chosen with phpunit from the app folder. Learn more about Testing in CakePHP 2

Ensure that you have installed the vendor dependencies for this plugin through composer or some other means.

./Console/cake testsuite Chosen View/Helper/ChosenHelper


Chosen inputs behave identically to the FormHelper::input() method.


echo $this->Chosen->select(
    array(1 => 'Category 1', 2 => 'Category 2'),
    array('data-placeholder' => 'Pick categories...', 'multiple' => true)

Default selected:

echo $this->Chosen->select(
    array(1 => 'Category 1', 2 => 'Category 2'),
        'data-placeholder' => 'Pick categories...',
        'default' => 1,


echo $this->Chosen->select(
        'NFC East' => array(
            'Dallas Cowboys',
            'New York Giants',
            'Philadelphia Eagles',
            'Washington Redskins'
        'NFC North' => array(
            'Chicago Bears',
            'Detroit Lions',
            'Greenbay Packers',
            'Minnesota Vikings'
        // ....
        'data-placeholder' => 'Pick your favorite NFL team...',
        'style' => 'width: 350px'

Deselect on Single Select:

    array('data-placeholder' => 'Please select...', 'deselect' => true),

Do not use 'empty' => 'Please Select...' attribute with deselect, use 'data-placeholder' => 'Please Select...' instead.


Copyright 2013 Paul Redmond. It is free software, and may be redistributed under the terms specified in the LICENSE file. License is also available online.

Something went wrong with that request. Please try again.