Date select
From PHP on Trax
date_select( string $object_name, string $attribute_name, array $options = array() )
Description
Returns a set of select tags (one for year, month, and day) pre-selected for accessing a specified date-based attribute (identified by $attribute_name) on an object assigned to the template (identified by $object_name). It’s possible to tailor the selects through the $options array, which accepts all the keys that each of the individual select builders do (like use_month_numbers for select_month) as well as a range of discard options. The discard options are discard_year, discard_month and discard_day. Set to true, they’ll drop the respective select. Discarding the month select will also automatically discard the day select.
Passing disabled => true as part of the options will make elements inaccessible for change.
NOTE: Discarded selects will default to 1. So if no month select is available, January will be assumed.
$object_name a string which is the name of the instanciated model object in your controller that you want date_select to access for the "value".
$attribute_name a string which is the name of the column in the database table or object's attribute you want text_field to access for the "value".
$options is an array of key => value pairs of options for the select.
Examples
In your controller
<?
class BlogController extends ApplicationController {
function edit() {
$post = new Post;
$this->post = $post->find($_REQUEST['id']);
..
..
..
}
}
?>
In your view edit.phtml
<?= date_select("post", "written_on") ?>
<?= date_select("post", "written_on", array("start_year" => 1995)) ?>
<?= date_select("post", "written_on", array("start_year" => 1995,
"use_month_numbers" => true,
"discard_day" => true,
"include_blank" => true)) ?>
