したがって、次のような配列があります。
$grades =
Array(
[0] => Array ( [Grade] => Array ( [id] => 0 [name] => Kindegarten ) )
[1] => Array ( [Grade] => Array ( [id] => 1 [name] => First ) )
[2] => Array ( [Grade] => Array ( [id] => 2 [name] => Second ) )
[3] => Array ( [Grade] => Array ( [id] => 3 [name] => Third ) )
[4] => Array ( [Grade] => Array ( [id] => 4 [name] => Fourth ) )
[5] => Array ( [Grade] => Array ( [id] => 5 [name] => Fifth ) )
)//End array
キー(最初の0〜5)を任意に選択する方法はありますか?CakePHP はこのようにテーブルの項目を返しますが、オプションを使用してフォーム ヘルパーの印刷にどのように適合させることができるかわかりません。
echo $this->Form->input('grade_selection',
array('type' => 'radio', 'options' => array($grades[?]['Grade']['id'] => $grades[?]['Grade']['name'])));
? 配列内の各項目を取得できるように、オプションで変更する方法はありますか?
class GradesController extends AppController {
public function index(){
//Gets all the rows in the grade table and stores it into a variable called grade.
//$grades = $this->Grade->find('all');
$grades = $this->Grade->getGrades();
//Returns the $grades variable when it is requested.
if($this->request->is('requested')){
return $grades;
}
//Sends the $grades variable to the view file. The string 'grades' is the name of the variable that the Grades View file will have the same setup as the $grades.
$this->set('grades', $grades);
}
}