Symfony Cheat Sheet

ADVERTISEMENT

Open-Source PHP5 MVC Framework
Agile Development
Helpers
PART 2 - FORMS
FORM HELPERS
FORM HELPERS FOR OBJECTS
Standard Helper
<?php echo use_helper('Object’) ?>
FORM TAG
Add the
object_
prefix in front of the name
form_tag($url, $options)
of the form helpers to get the name of the
related object form helper:
<?php echo form_tag('test/save', Array('method' => 'get', 'id' => 'myForm', 'class' => 'simpleForm'))?>
object_input_tag($parameters)
// options argument with the associative array syntax
object_textarea_tag($parameters)
<?php echo form_tag('test/save', ‘method=get id=myForm class=simpleForm')?>
object_checkbox_tag($parameters)
// options argument with the string syntax
object_input_date_tag($parameters)
objects_for_select($parameters)
STANDARD FORM ELEMENTS
object_select_tag($parameters)
label_for($id, $label, $options)
object_select_country_tag($parameters)
Returns a <label> tag with for the specified parameter.
object_select_language_tag($parameters)
object_input_hidden_tag ($parameters)
input_tag ($name, $value=null, $options)
The
$parameters
(for all object helpers) are:
<?php echo input_tag('name', 'default value') ?>
($object, $method,
$options
, $default_value)
// will generate in HTML: <input type="text" name="name" id="name" value="default value" />
input_hidden_tag($name, $value, $options)
E.g.1: the text input tag looks like:
<?php echo object_input_tag($customer,
<?php echo input_hidden_tag('name', 'value') ?>
'getTelephone') ?>
input_password_tag ($name= 'password', $value=null, $options)
// will generate in HTML
<?php echo input_password_tag('name', 'value') ?>
<input type="text" name="getTelephone"
id="getTelephone" value="0123456789" />
rich
textarea_tag ($name, $content=null, $options)
...provided that
<?php echo textarea_tag('name', 'default content', 'size=10x20') ?>
$customer->getTelephone()= '0123456789'
// will generate in HTML:
<textarea name="name" id="name" rows="20" cols="10">default content</textarea>
E.g.2: picture a form built to edit the data
of an article. There is an easy way to get the
checkbox_tag ($name, $value, $checked=false, $options)
list of the author with the “related_class”:
<?php echo checkbox_tag('married', '1', true) ?>
object_select_tag($article, 'getAuthorId',
<?php echo checkbox_tag('driverslicence', 'B', false) ?>
'related_class=Author')
// will generate in HTML:
Symfony will use the
->toString()
method of
<input type="checkbox" name="married" id="married" value="1" checked="checked" />
<input type="checkbox" name="driverslicence" id="driverslicence" value="B" />
the Author class to display the names of the
authors in a list. If the method is undefined,
radiobutton_tag ($name, $value, $checked=false, $options)
the primary key (in the example, the id
<?php echo radiobutton_tag('status', 'value1', true) ?>
column) of the Author table is used instead.
<?php echo radiobutton_tag('status', 'value2', false) ?>
// will generate in HTML:
Other list options:
<input type="radio" name="status" value="value1" checked="checked" />
include_blank
<input type="radio" name="status" value="value2" />
to add a first empty line to the list
object_select_tag($article, 'getAuthorId',
select_tag ($name, $option_tags=null, $options)
‘related_class=Author include_blank')
options_for_select ($options=array(), $selected= '', $html_options)
include_title
<?php echo select_tag('name', options_for_select(Array('0' => 'Steve', '1' => 'Bob', '2' => 'Albert',
to add a title in the first line of the list
'3' => 'Ian'), 3)) ?>
object_select_tag($article, 'getAuthorId',
input_file_tag ($name, $options)
‘related_class=Author include_title')
<?php echo input_file_tag('name') ?>
include_custom
submit_tag($value, $options)
// submit button (as text)
includes an <option> tag with a custom display
text in the first line of the list
<?php echo submit_tag('Save') ?>
object_select_tag($article, 'getAuthorId',
submit_image_tag($source, $options)
// submit button (as image)
‘related_class=Author include_custom=select')
<?php echo submit_image_tag('submit_img') ?>
// will generate in HTML: <input type="image" name="submit" src="/images/submit_img.png" />
input_upload_tag ($name, $options)
RICH FORM ELEMENTS
rich
rich
input_date_tag ($name, $value, $options)
reset_tag ($value= 'Reset', $options)
<?php echo input_date_tag('dateofbirth',
‘2005-05-03', 'rich=true') ?>
rich
select_country_tag ($name, $value, $options)
// will generate in HTML:
select_language_tag ($name, $value, $options)
// a text input tag together with a calendar widget
Returns a <select> tag populated with all the languages in the world (or almost).
<?php echo textarea_tag('name', 'default
select_day_tag ($name, $value, $options, $html_options)
content', 'rich=true size=10x20')) ?>
select_month_tag ($name, $value, $options, $html_options)
// will generate in HTML:
// a rich text edition zone powered by TinyMCE
select_year_tag ($name, $value, $options, $html_option)
select_date_tag ($name, $value, $options, $html_options)
<?php echo select_country_tag('country',
‘Albania') ?>
select_second_tag ($name, $value, $options, $html_options)
// will generate in HTML:
select_minute_tag ($name, $value, $options, $html_options)
<select name="country" id="country">
select_hour_tag ($name, $value, $options, $html_options)
<option>Afghanistan</option>
<option selected="selected">Albania</option>
select_ampm_tag ($name, $value, $options, $html_options)
<option>Algeria</option>
select_time_tag ($name, $value, $options, $html_options)
<option>American Samoa</option>
select_datetime_tag ($name, $value, $options, $html_options)
...
This cheat-sheet is not an official part of the symfony documentation

ADVERTISEMENT

00 votes

Related Articles

Related forms

Related Categories

Parent category: Education
Go