Ajax
Estou a tentar pôr a funcionar o ajax mas não estou a conseguir.
No controller tenho :
class PostsController extends AppController {
var $name = "Posts";
var $helpers = array('Html','Ajax','Javascript');
var $components = array( 'RequestHandler' );
function index() {
$this->set('posts', $this->Post->find('all'));
}
function deleteaj($id) {
$this->Session->setFlash('passou');
}
a view index contendo a lista de posts dentro do div a actualizar e o link ajax
<?php echo $ajax->div('postsdiv'); ?>
<table>
<tr>
<th>Id</th>
<th>Title</th>
<th>Actions</th>
<th>Created</th>
</tr>
<!-- Here's where we loop through our $posts array, printing out post info -->
<?php foreach ($posts as $post): ?>
<tr>
<td><?php echo $post['Post']['id']; ?></td>
<td>
<?php echo $html->link($post['Post']['title'], array('action' => 'view', 'id' => $post['Post']['id'])); ?>
</td>
<td>
<?php echo $html->link('Delete', array('action' => 'delete', $post['Post']['id']), null, 'Are you sure?') ?>
<?php echo $html->link('Edit', array('action' => 'edit', $post['Post']['id'])); ?>
<?php
echo $ajax->link('Excluir Post',
array( 'controller' => 'posts', 'action' => 'deleteaj', $post['Post']['id']) ,
array( 'update' => 'postsdiv' ), 'Você quer mesmo excluir este post?'); ?>
</td>
<td><?php echo $post['Post']['created'];
?></td>
</tr>
<?php endforeach; ?>
</table>
<?php echo $ajax->divEnd('postsdiv'); ?>
o default.ctp tem a inclusão dos js
echo $javascript->link('prototype');
echo $javascript->link('scriptaculous');
contudo quando clico no link dá o seguinte erro
Notice (8): Undefined variable: javascript [APP\views\layouts\default.ctp, line 33]
Fatal error: Call to a member function link() on a non-object in C:\xampp\htdocs\cakephp\blog\views\layouts\default.ctp on line 33
agora substitui no default ctp por
echo $this->Html->script('prototype');
echo $this->Html->script('scriptaculous');
mas quando clico no link n faz nada,devia ao menos aparecer o session flashDiscussão (3)
Carregando comentários...