FormHelper(ケーキ1.3)を使用して、配列から選択ボックスを作成しています。配列は数値をキーとして使用しますが、選択ボックスはそれらの数値を無視し、選択ボックスのオプション値にはゼロベースのインデックスを使用します。私は両方の(文字列)$キーとstrval($キー)を使用して文字列に配列キーを入力しようとしたが運がない。選択オプションは、数字キーの前に文字を追加すると機能しますが(つまり、 'c'。$ key)、このハックを避けたいと思います。CakePhpで数値キーを使用するFormHelper Select
FormHelperに文字の前に実際の数字キーを使用させる方法はありますか?どんな助けもありがとう。
イラストについては、以下のコードを参照してください:
// $category_list looks like this
Array
(
[164] => Antiques & Art
[83] => Baby/Children Needs
[176] => Boats/Marine/Fishing
[222] => Books & Magazines
[287] => Building Materials
[215] => Business
[175] => Caravans & Motor Homes
[169] => Cars & Other Vehicles
[127] => Clothing & Accessories
[92] => Computers & Electronics
[358] => Farm & Agriculture
[235] => Garage Sales/Yard Sales
[309] => Garden & Yard
[178] => General Merchandise
[138] => Health & Beauty
[186] => Hobbies & Collectables
[63] => Household
[234] => Information
[388] => Motorbikes & Scooters
[206] => Musical Instruments
[449] => Notices
[305] => Pets and Accessories
[242] => Positions Vacant
[236] => Real Estate & Rentals
[243] => Services
[143] => Sports Equipment
[308] => Tools & Equipment
[300] => Travel & Holiday
)
// Output category select box
echo $form->select(
'category',
$category_list,
$category,
array('id'=>'SearchCategories')
);
// Outputs like this
<option value="1">Antiques & Art</option>
<option value="2">Baby/Children Needs</option>
<option value="3">Boats/Marine/Fishing</option>
<option value="4">Books & Magazines</option>
...
// I'd like it to output like this
<option value="164">Antiques & Art</option>
<option value="83">Baby/Children Needs</option>
<option value="176">Boats/Marine/Fishing</option>
<option value="222">Books & Magazines</option>
...
'debug($ this-> find( 'all'))'または 'debug($ this-> find ( 'list')) '' $ category_list'を表示する – RSK