Repeatable field in simple module
Hi to all
I'm create simple module named events, that must display page with text, google map, date start, date end and image galery.
And I'm try to create field for image galery with repeatable ability (like in layouts with properhy 'repeatable' => TRUE).
How can I do this?
Sorry for my bad english.
Comments
I used the field "template" with params - 'repeatable' => true, for such purposes.
Where to write a layout parameters in it?
When I save data in admin panel in my Events model, nothing go to the database.
I'm use fuel cms version 1.3
Here database field to store image galery:
'slider_image' text NOT NULL
And Events_model class:
class Events_model extends Base_module_model {
public $serialized_fields = array('slider_image');
function __construct() {
parent::__construct('events');
}
function form_fields($values = array(), $related = array()) {
$fields = parent::form_fields($values, $related);
$fields['slider_image'] = array(
'display_label' => TRUE,
'type' => 'template',
'repeatable' => TRUE,
'label' => 'Images Galery',
'name' => 'galery',
'fields' =>
array(
'image' => array('type' => 'image')
)
);
return $fields;
}
}
All other fields like title, date, text save normaly, problem only with slider_image repeatable field.
Please help me to solve this problem with store repeatable field in database.
'name' => 'galery',
Please tell me what do I do wrong?
The problem was that it is impossible to name a repeatable field came to an end in an _image or _img
And thanks to Andrew, if don't remove 'name' property data don't save to database.
you can use 'type' => 'asset' for this purpose
but if you strongly want to use type 'image',
you you can define it in /fuel/modules/fuel/config/custom_fields.php
// Asset field $fields['asset'] = array( 'class' => array(FUEL_FOLDER => 'Fuel_custom_fields'), 'function' => 'asset', 'filepath' => '', 'js_function' => 'fuel.fields.asset_field', 'represents' => array('name' => '.*image\]?$|.*img\]?$', 'type' => 'image'), );
$slide_image[0]['image'] = 'my_image1.jpg'; $slide_image[1]['image'] = 'my_image2.jpg' $slide_image[02]['image'] = 'my_image3.jpg'
Because it is this nested array syntax, the data needs to be serialized or handled with a mode