salut svp aidé moi, j ss bloqué :( (j travail avec cakephp 2.3.0)
je veux faire un multi suppression de mes Clients et voila mon code qui ne fonctione pas, message error:
Notice (8): Undefined index: element [CORE\Cake\View\Helper\SessionHelper.php, line 131]
dans mon AppController.php
var $multiActions = array();
function multi() {
if (!isset($this->data'action']) || !count($this->data'action'])) {
$this->_flash(__('Action was not defined in request.', true),'error');
$this->redirect($this->referer(), null, true);
}
foreach ($this->data'action'] as $action=>$v){}
if (!in_array($action,(array)$this->multiActions)) {
$this->_flash(__(sprintf('Action %s is not allowed.',$action), true),'error');
$this->redirect($this->referer(), null, true);
}
if (!method_exists($this,$action)) {
$this->_flash(__(sprintf('Action %s is invalid.',$action), true),'error');
$this->redirect($this->referer(), null, true);
}
$this->$action();
}
function admin_multi() {
$this->multi();
}
function _flash($message,$type='message') {
$messages = (array)$this->Session->read('Message.multiFlash');
$messages] = array('message'=>$message, 'layout'=>'default', 'params'=>array('class'=>$type));
$this->Session->write('Message.multiFlash', $messages);
}
dans mon ClientsController.php
var $name = 'Clients';
var $multiActions = array('admin_multi_delete');
function admin_multi_delete() {
if (!isset($this->params'form']'record']) || !count($this->params'form']'record'])) {
$this->_flash(__('No records selected.', true),'warning');
$this->redirect($this->referer(), null, true);
}
$ids = array();
foreach ($this->params'form']'record'] as $id=>$v) {
if ($v == 1) {
if ($this->Client->del($id)) {
$this->_flash(__(sprintf('Deleted record %d.',$id),true),'success');
}
else {
$this->_flash(__(sprintf('Could not delete record %d.',$id),true),'error');
}
}
}
$this->redirect($this->referer(), null, true);
}
dans default.ctp
<div id="messages">
<?php
if ($this->session->check('Message.flash')) $this->session->flash();
if ($messages = $this->session->read('Message.multiFlash')) {
foreach($messages as $k=>$v) $this->session->flash('multiFlash.'.$k); }
?>
</div>
dans views/Clients/index.ctp
<?= $this->form->create('Client',array('id'=>'ClientListForm','url'=>array('controller'=>'Clients','action'=>'multi')));?>
<div class="box-content" >
<table class="table table-striped table-bordered bootstrap-datatable datatable">
<thead>
<tr>
<th><span class="select_all">a</span>|<span class="select_none">n</span></th>
<th><?= $this->paginator->sort(__('id',true),'id');?></th>
<th><?= $this->paginator->sort(__('nom_cli',true),'name');?></th>
<th><?= $this->paginator->sort(__('ville_cli',true),'Ville');?></th>
<th class="actions"><?php __('Actions');?></th>
</tr>
</thead>
<tbody>
<?php
$i = 0;
foreach ($Clients as $Client):
$class = ($i&1)?' class="altrow"':'';
?>
<tr<?php echo $class;?>>
<td>
<?= $this->form->input($Client'Client']'id'],array(
'type'=>'checkbox',
'label'=>false,
'name'=>'record'.$Client'Client']'id'].']',
'id'=>'listRecord_'.$Client'Client']'id'],
)); ?>
</td>
<td>
<?= $Client'Client']'id']; ?>
</td>
<td>
<?= $Client'Client']'nom_cli']; ?>
</td>
<td>
<?= $Client'Client']'ville_cli']; ?>
</td>
<td class="actions">
<?= $this->html->link(__('View', true), array('action'=>'view', $Client'Client']'id'])); ?>
<?= $this->html->link(__('Edit', true), array('action'=>'edit', $Client'Client']'id'])); ?>
<?= $this->html->link(__('Delete', true), array('action'=>'delete', $Client'Client''id']),null,
sprintf(__('Are you sure you want to delete # %s?', true), $Client'Client']'id']));
?>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
<div class="multi_actions">
<input type="submit" name="data[action][admin_multi_delete]" value="Delete" onclick="return confirm('<?php __('Are you sure you want to delete
the selected records?'); ?>');"/>
</div>
<?= $this->form->end();?>
et Merciiiiiiiiiiiiii ^^
Salut
Je viens de répondre à un problème similaire ici --> http://www.grafikart.fr/forum/topic/12986
Tu peux analyser le code sans soucis la réponse est donnée.