0

admin_add_newsletter.ctp

foreach($menu_page_1 as $menu_pages) {
    echo $this->Form->checkbox('top_links.',array(
        'type'=>'checkbox','id'=>'checked_box',
        'value'=>$menu_pages['MenuPage']['id'],
        'label'=>false,'div'=>false,'hiddenField'=>false,
        'saparator'=>'</td><td>'
    ));
    echo '<label for="top_links'.$menu_pages['MenuPage']['id'].'">'.
        $menu_pages['MenuPage']['name'].'</label>';
}

通讯控制器.php

if($this->request->is('post')) {
    print_r($this->data['Newsletter']['top_links']['']);
    exit();
}

错误

The request has been black-holed

Error: The requested address '/admin/newsletters/add_newsletter' was not found on this server.

Stack Trace
CORE/Cake/Controller/Component/SecurityComponent.php line 239 → SecurityComponent->blackHole(NewslettersController, string)
[internal function] → SecurityComponent->startup(NewslettersController)
CORE/Cake/Utility/ObjectCollection.php line 132 → call_user_func_array(array, array)
[internal function] → ObjectCollection->trigger(CakeEvent)
CORE/Cake/Event/CakeEventManager.php line 247 → call_user_func(array, CakeEvent)
CORE/Cake/Controller/Controller.php line 675 → CakeEventManager->dispatch(CakeEvent)
CORE/Cake/Routing/Dispatcher.php line 182 → Controller->startupProcess()
CORE/Cake/Routing/Dispatcher.php line 160 → Dispatcher->_invoke(NewslettersController, CakeRequest, CakeResponse)
APP/webroot/index.php line 108 → Dispatcher->dispatch(CakeRequest, CakeResponse)

帮助我了解如何在 cakephp 中使用复选框,其中包含从视图文件到控制器的所有检查值,而不会显示黑洞错误。

4

1 回答 1

0

问题是您正在手动构建复选框选项,并在字段名称中添加一个点。

做到这一点的方法是这样做的蛋糕方式

$options = array();

foreach($menu_page_1 as $menu_pages) {
    $options[$menu_pages['MenuPage']['id']] = $menu_pages['MenuPage']['name'];
}
echo $this->Form->select('top_links', $options, array(
    'multiple' => 'checkbox'
));
于 2014-04-10T08:54:46.643 回答