我有一張訂單來取代優惠券,但由於某種原因,現在當我點擊phurcase時,它會顯示一個空白屏幕。我不能看到什麼改變了,爲什麼視圖沒有被傳遞來自控制器的信息。cakephp視圖將不會顯示
Vourchers形式
<h2>Vouchers</h2>
<?php
foreach($vouchers as $v){
?>
<div id="voucher_box" class="add_shadow column span-8">
<h3><?=$v['Voucher']['title'];?></h3>
<p>
<?=$v['Voucher']['description'];?>
</p>
<?php
echo $this->Form->create('Voucher',array('id'=>'ResVoucherForm','url'=>'/res/voucher'));
echo $this->Form->input('slug',array('type'=>'hidden','value'=>$v['Voucher']['slug']));
?>
<select id="VoucherPrice" name="data[Voucher][price]">
<? $prices = explode(',',$v['Voucher']['prices'])?>
<? foreach($prices as $price){?>
<option value="<?=$price?>">€ <?=$price?></option>
<? } ?>
</select>
<div class="submit"><input type="submit" id="check_rates" value="Purchase this" class="ui-button ui-widget ui-state-default ui-corner-all" /></div>
</form>
</div>
<?
}
?>
控制器
function voucher() {
$this->layout = '360';
$msg[0] = array(); // 0 = bad messages
$msg[1] = array(); // 1 = good messages
$total_price = 0.00;
if(isset($data['Voucher'])) { $this->data['Voucher'] = $data['Voucher']; }
if(isset($this->data['Voucher'])) {
// if we have posted a voucher purchase: add it to session array
if(isset($this->data['Voucher']['slug'])){
$slug = $this->data['Voucher']['slug'];
$voucher = $this->getVoucher($slug);
$voucher['Voucher']['price'] = $this->data['Voucher']['price'];
$vouchers = $this->Session->read('Res.Vouchers'); // read existing voucher orders
if(is_array($vouchers) && isset($voucher['Voucher'])){
$temp['id'] = $voucher['Voucher']['id'];
$temp['title'] = $voucher['Voucher']['title'];
$temp['description'] = $voucher['Voucher']['description'];
$temp['slug'] = $voucher['Voucher']['slug'];
$temp['price'] = $this->data['Voucher']['price'];
$vouchers[] = $temp;
}
$this->Session->write('Res.Vouchers',$vouchers);
} else {
$vouchers = $this->Session->read('Res.Vouchers'); // read existing voucher orders
}
$this->set('voucher_orders', $vouchers);
}
接下來的這個視圖顯示空白,我不知道如何在控制器
<?php
/*
if voucher show
*/
if (isset($voucher)) {
?>
<div id="voucher_box" class="add_shadow column span-8">
<h3><?=$voucher['Voucher']['title'];?></h3>
<p>
<?=$voucher['Voucher']['description'];?>
</p>
<?php
echo $this->Form->create('Voucher',array('id'=>'ResVoucherForm','url'=>'/res/voucher'));
echo $this->Form->input('slug',array('type'=>'hidden','value'=>$voucher['Voucher']['slug']));
?>
<select id="VoucherPrice" name="data[Voucher][price]">
<? $prices = explode(',',$voucher['Voucher']['prices'])?>
<? foreach($prices as $price){?>
<option value="<?=$price?>">€ <?=$price?></option>
<? } ?>
</select>
<div class="submit"><input type="submit" id="check_rates" value="Purchase this" class="ui-button ui-widget ui-state-default ui-corner-all" /></div>
</form>
</div>
<?
}
// end if voucher show
?>
Upadate返回錯誤#考信息################################################## ####
通知(8):未定義指數:ID [APP /控制器/ res_controller.php,線739]
通知(8):未定義指數:標題[APP /控制器/ res_controller.php,線740]
通知(8):未定義指數:描述[APP /控制器/ res_controller.php,線741]
通知(8):未定義指數:蛞蝓[APP /控制器/ res_controller.php,線742]
Array ( [0] => Array ( [ID] => [標題] => [描述] => [蛞蝓] => [價格] => 100 )
)
您是否啓用了調試功能?如果沒有在core.php中將debug設置爲2並檢查錯誤輸出。您也可以使用pr()或debug()函數(如pr($ this-> data))在您的控制器中輸出,例如 – 8vius
感謝您的幫助,我非常不確定測試控制器中的數據。我在$ this-> set('voucher_orders',$ vouchers)下完成了一個pr($ vouchers)。我發佈了這個錯誤,我沒有看到有什麼不對,因爲它之前很好。 –