Demo
年月日
View&CSS3
<div class="cake3_select_form_birthday3">
<?php
echo "<select name=\"birth_year\">{$birth_year}</select>年<select name=\"birth_month\">{$birth_month}</select>月<select name=\"birth_day\">{$birth_day}</select>日";
?>
</div>
.cake3_select_form_birthday3 select{
width: 4rem;
outline: none;
padding: 0.3rem 0;
margin: 0 0.2rem 0 0.5rem;
border: 1px solid #ccc;
}
.cake3_select_form_birthday3 select:first-child{
margin-left: 0rem;
}
Controller
public function index(){
// 使用している変数名
// $d, $this_year, $start_year, $birth_year, $birth_month, $birth_day, $i
$d = date_create();
$this_year = date_format($d, "Y");
$start_year = $this_year - 100;
$birth_year = $birth_month = $birth_day = "<option value=\"\">--</option>";
for($i = $start_year; $i <= $this_year; $i++){
$birth_year .= "<option value=\"{$i}\">{$i}</option>";
}
for($i = 1; $i <= 12; $i++){
$i = sprintf('%02d', $i);
$birth_month .= "<option value=\"{$i}\">{$i}</option>";
}
for($i = 1; $i <= 31; $i++){
$i = sprintf('%02d', $i);
$birth_day .= "<option value=\"{$i}\">{$i}</option>";
}
$this->set(compact('birth_year', 'birth_month', 'birth_day'));
}