Skip to content

Instantly share code, notes, and snippets.

@McGaiser
Created December 18, 2015 11:40
Show Gist options
  • Save McGaiser/ef74443e0e8035104581 to your computer and use it in GitHub Desktop.
Save McGaiser/ef74443e0e8035104581 to your computer and use it in GitHub Desktop.
Issues saving stuff
Controller:
public function editPrestige($id=null){
$prestigeLog = $this->PrestigeLogs->find()
->contain([
'Members.Domains',
'PrestigeLogsItems'=> function ($q){
return $q->where(['approved_id IS NULL']);
}
])
->where(['PrestigeLogs.id'=>$id])
->first()
;
debug($prestigeLog);
debug($this->request->data());
$prestigeLogsItems = $prestigeLog->prestige_logs_items;
if ($this->request->is(['post', 'put'])) {
//Update the object with request data.
$this->PrestigeLogs->PrestigeLogsItems->patchEntities($prestigeLogsItems, $this->request->data());
if ($result = $this->PrestigeLogs->PrestigeLogsItems->save($prestigeLogsItems)) {
$this->Flash->success(__('The Prestige Log Items has been updated.'));
return $this->redirect(['action' => 'view', $id]);
}
$this->Flash->error(__('Unable to update the prestigeLog.'));
}
$affiliateId = $this->PrestigeLogs->PrestigeLogsItems->PrestigeItems->PrestigeCategories->Affiliates->getAffiliateIdByDomainId($this->request->session()->read('Auth.User.domain_id'));
$prestigeItems = $this->PrestigeLogs->PrestigeLogsItems->PrestigeItems->getPrestigeItemsList($affiliateId);
$domains = $this->PrestigeLogs->PrestigeLogsItems->Domains->find('list')->toArray();
$venues = $this->PrestigeLogs->PrestigeLogsItems->Venues->find('list')->contain(['Games'])->group(['Games.id'])->toArray();
$this->set(compact('prestigeLog', 'prestigeLogsItems', 'prestigeItems', 'domains', 'venues'));
}
Post data:
[
(int) 0 => [
'prestige_log_id' => '1',
'prestige_item_id' => '1',
'domain_id' => '7',
'venue_id' => '',
'amount' => '45',
'reason' => 'October 2015'
],
(int) 1 => [
'prestige_log_id' => '1',
'prestige_item_id' => '3',
'domain_id' => '7',
'venue_id' => '',
'amount' => '10',
'reason' => 'I am just that good!'
]
]
View:
<!-- src/Template/PrestigeLogs/edit_prestige.ctp -->
<div id='content'>
<H1>Prestige Log</H1>
<dl>
<dt><?= __('Name'); ?></dt>
<dd><?= $this->Html->link(h($prestigeLog['member']['full_name']), ['action' => 'view', h($prestigeLog['member']['id'])] ); ?>&nbsp;</dd>
</dl>
<dl>
<dt><?= __('Domain'); ?></dt>
<dd><?= $this->Html->link(h($prestigeLog['member']['domain']['name']), ['action' => 'view', h($prestigeLog['member']['domain']['id'])] ); ?>&nbsp;</dd>
</dl>
<dl>
<dt><?= __('Log'); ?></dt>
<dd>
<table border="1">
<tr>
<th>Item</th>
<th>Domain</th>
<th>Venue</th>
<th>Amount</th>
<th>Reason</th>
</tr>
<div class="prestigeLogsItems form">
<?= $this->Form->create($prestigeLogsItems) ?>
<fieldset>
<legend><?= __('Edit Prestige Item') ?></legend>
<?php foreach( $prestigeLogsItems as $index=>$prestigeLogsItem ): ?>
<tr>
<?= $this->Form->hidden($index.'.prestige_log_id') ?>
<td><?= $this->Form->input($index.'.prestige_item_id', ['label'=>false]) ?></td>
<td><?= $this->Form->input($index.'.domain_id', ['label'=>false]) ?></td>
<td><?= $this->Form->input($index.'.venue_id', ['label'=>false, 'empty'=>"None"]) ?></td>
<td><?= $this->Form->input($index.'.amount', ['label'=>false]) ?></td>
<td><?= $this->Form->input($index.'.reason', ['label'=>false]) ?></td>
</tr>
<?php endforeach; ?>
</fieldset>
</table>
<?= $this->Form->button(__('Submit')); ?>
<?= $this->Form->end() ?>
</div>
</dd>
</dl>
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment