所以,我有一个看起来像这样的数组:
$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);
}
}