この質問がどこかで答えられた場合はお詫びします、私はそれを見つけようとしましたが、役に立ちませんでした
Cakephpは通常私の友達ですが、今は気が狂っています。他の多くのエントリが存在する同じページでエントリを投票するオプションを作成しようとしています。私はこれをCake1.3で100万回実行しました
問題: ページに10個のエントリがある場合(一意のdivでラップされている場合)、entry_idがコントローラー(FireBug)で正しく受信され、デバッグで$ this-> request-が示されていても、最初のエントリを「スコアリング」することしかできません。 >データは正しいです。それでも、Cakeはページの最初のエントリの「スコア」のみを保存し、リンクをクリックした後、他のエントリのスコアのエラーメッセージを表示しません。
UpdateALLアクションはすべてのエントリに対して正しく実行され、SAVEアクションのみが失敗します。
質問: +リンクをクリックすると、Cakeがページ上のすべてのエントリのスコアを保存しないのはなぜですか。この場合も、エラーメッセージはスローされません。
コントローラ:
public function score($id = null)
{
if ($this->Auth->user('id')) {
if ($this->Entry->updateAll(array('Entry.score' => 'Entry.score+1'), array('Entry.id' => $id))) {
$this->Entry->Score->create();
$this->request->data['Score']['entry_id'] = $id;
$this->request->data['Score']['user_id'] = $this->Auth->user('id');
if ($this->Entry->Score->save($this->request->data)) {
$total_scored = $this->Entry->find('first', array('conditions' => array('Entry.id' => $id)));
$this->Entry->contain();
$this->set('total_scored', $total_scored);
if ($this->request->is('ajax')) {
$this->render('_scored', 'ajax');
} else {
$this->redirect(array('action' => 'index'));
}
}
}
}
}
意見:
<div class="scoreButton-<?php echo $entry['Entry']['id'];?>">
<?php if (((AuthComponent::user('id')) && ($entry['Entry']['user_id'] !== AuthComponent::user('id')))): ?>
<p class="monster l20 t25 hover"><?php echo $this->Js->link('+','/entries/score/' . $entry['Entry']['id'] . '', array('update' => '.scored-' . $entry['Entry']['id'] . '', 'complete' => $this->Js->get('.scoreButton-' . $entry['Entry']['id'] . '')->effect('hide'))); ?>
</p>
</div>
<div class="scored-<?php echo $entry['Entry']['id'];?>"> </div>
<?php endif;?>
<?php if (!AuthComponent::user('id')): ?>
<p class="monster grey l20 t25">+</p>
<?php endif;?>