CaptchaBundle/README.md

142 lines
3.0 KiB
Markdown
Raw Normal View History

2011-08-25 23:13:27 +02:00
Gregwar's CaptchaBundle
=====================
The `GregwarCaptchaBundle` adds support for a "captcha" form type for the
Symfony2 form component.
2011-08-25 23:13:27 +02:00
Installation
============
### Step 1: Download the GregwarCaptchaBundle
2011-08-25 23:13:27 +02:00
Ultimately, the GregwarCaptchaBundle files should be downloaded to the
'vendor/bundles/Gregwar/CaptchaBundle' directory.
You can accomplish this several ways, depending on your personal preference.
The first method is the standard Symfony2 method.
2011-09-09 14:28:13 +02:00
***Using the vendors script***
Add the following lines to your `deps` file:
```
2011-08-25 23:13:27 +02:00
[GregwarCaptchaBundle]
git=git://github.com/Gregwar/CaptchaBundle.git
target=/bundles/Gregwar/CaptchaBundle
```
2011-08-25 23:13:27 +02:00
Now, run the vendors script to download the bundle:
2011-08-25 23:13:27 +02:00
``` bash
$ php bin/vendors install
```
***Using submodules***
2011-09-09 14:28:13 +02:00
If you prefer instead to use git submodules, then run the following:
``` bash
$ git submodule add git://github.com/Gregwar/CaptchaBundle.git vendor/bundles/Gregwar/CaptchaBundle
$ git submodule update --init
```
### Step 2: Configure the Autoloader
Now you will need to add the `Gregwar` namespace to your autoloader:
``` php
2011-08-25 23:13:27 +02:00
<?php
// app/autoload.php
$loader->registerNamspaces(array(
// ...
'Gregwar' => __DIR__.'/../vendor/bundles',
));
2011-08-25 23:13:27 +02:00
```
### Step 3: Enable the bundle
2011-08-25 23:13:27 +02:00
Finally, enable the bundle in the kernel:
2011-08-25 23:13:27 +02:00
```php
<?php
// app/appKernel.php
2011-08-25 23:13:27 +02:00
public function registerBundles()
{
$bundles = array(
// ...
2011-08-25 23:13:27 +02:00
new Gregwar\CaptchaBundle\GregwarCaptchaBundle(),
);
}
2011-08-25 23:13:27 +02:00
```
2011-09-09 14:28:13 +02:00
Configuration
=============
Add the following configuration to your `app/config/config.yml`:
2011-08-25 23:13:27 +02:00
gregwar_captcha: ~
Usage
=====
You can use the "captcha" type in your forms this way:
```php
<?php
// ...
$builder->add('captcha', 'captcha'); // That's all !
// ...
```
Note that the generated image will be embeded in the HTML document, to avoid dealing
with route and subrequests.
2011-09-09 20:06:17 +02:00
You can define the following type option :
* **width**: the width of the captcha image (default=120)
* **height**: the height of the captcha image (default=40)
* **length**: the length of the captcha (number of chars, default 5)
Example :
```php
<?php
// ...
$builder->add('captcha', 'captcha', array(
'width' => 200,
'height' => 50,
'length' => 6
));
```
You can also set these options for your whole application using the `gregwar_captcha`
configuration entry in your `config.yml` file:
gregwar_captcha:
width: 200
height: 50
length: 6
Form theming
============
2011-09-09 14:28:13 +02:00
The widget support the standard symfony theming, see the [documentation](http://symfony.com/doc/current/book/forms.html#form-theming) for details on how to accomplish this.
The default rendering is:
```html
{% block captcha_widget %}
2011-09-09 14:28:13 +02:00
{% spaceless %}
<img src="{{ captcha_code }}" title="captcha" width="{{ captcha_width }}" height="{{ captcha_height }}" />
{{ form_widget(form) }}
2011-09-09 14:28:13 +02:00
{% spaceless %}
{% endblock %}
```
2011-08-25 23:13:27 +02:00
License
=======
This bundle is under the MIT license. See the complete license in the bundle:
LICENSE
2011-08-25 23:13:27 +02:00