Chapter 8 problems -- Looking for

7 messages Options
Embed this post
Permalink
npm

Chapter 8 problems -- Looking for

Reply Threaded More More options
Print post
Permalink
Missing Method in PostsController
Error: The action comments is not defined in controller PostsController
Error: Create PostsController::comments() in file: app\controllers\posts_controller.php.


It is looking for the add comments function in the wrong controller.
Here's my code from the view (I used the downloaded code just to make sure, it happens there too)

<?=$html->link('<h1>'.$post['Post']['name'].'</h1>','/posts/view/'.$post['Post']
['id'],null,null,false);?>
<p>Author: <?=$post['User']['firstname'];?> <?=$post['User']['lastname'];?></p>
<p>Date Published: <?=$post['Post']['date'];?></p>
<hr/>
<p><?=$post['Post']['content'];?></p>
<hr/>
<h2>Comments</h2>
<div id="comments">
<? foreach($comments as $comment): ?>
        <div class="comment">
                <p><?=$comment['Comment']['name'];?></p>
                <p><?=$comment['Comment']['content'];?></p>
        </div>
<? endforeach;?>
<?=$ajax->form('/comments/add','post',array('update'=>'comments'));?>
<?=$form->input('Comment.name');?>
<?=$form->input('Comment.content');?>
<?=$form->input('Comment.post_id',array('type'=>'hidden','value'=>$post['Post'][
'id']));?>
<?=$form->end('Add Comment');?>
</div>
Same problem

Re: Chapter 8 problems -- Looking for

Reply Threaded More More options
Print post
Permalink
Hello,
Am having the same problem and I have looked everywhere for solutions without luck. Could someone more knowledgeable in cakephp come to the rescue please?
npm

Re: Chapter 8 problems -- Looking for

Reply Threaded More More options
Print post
Permalink
Found the solution: $ajax->form('/comments/add','post',array('update'=>'comments','url'=>'/comments/add'));

I'm spending more time chasing down this sort of thing than I am actually progressing through the book. :(  
npm

Re: Chapter 8 problems -- Looking for

Reply Threaded More More options
Print post
Permalink
Seems weird you have to specify the url twice as the first argument then again in the options array.
davidgolding

Re: Chapter 8 problems -- Looking for

Reply Threaded More More options
Print post
Permalink
In reply to this post by npm
Sorry you've had to chase down things. I feel your pain... The Cake core has been adjusted since the book's publication, but that's a good thing; it means that Cake will be all that much better once the official 1.2 release makes it out of beta, etc. We wrestled with some of these questions during production, wondering how best to write the book knowing that anything could change in the near future. But I opted to get the book out there. At the time, there was no Cake book in English, and the Packt Book came out days before mine (I believe it was probably on their minds since my book was announced first, and they made no mention until theirs hit bookshelves, like it was their strategy to proclaim it as the first...). Documentation was sorely needed, and that was first priority.

Since then, the book.cake.org site has improved greatly, and another Cake book has come out ("Practical CakePHP Projects"). Sorry for the long story, but I hope it does at least put some of my writing in this book in perspective.

That said--more than you wanted, I know--I'm glad to see that you, and others, have come to this forum. I apologize for not keeping up with it as much; grad studies have me swamped as well as some pressing web assignments. But it looks like many others are here to help me in my attempts to keep up with the errata, for which I'm grateful.

OK--the question in this thread...

You shouldn't have to specify too much in the Ajax::form() function. I'm pretty sure

$ajax->form('Comment','post',array('url'=>array('controller'=>'comments','action'=>'add'),'update'=>'comments'));

should work.
--Dave

Author, "Beginning CakePHP: From Novice to Professional"

[ get your copy at: http://www.amazon.com/Beginning-CakePHP-Novice-Professional/dp/1430209771/ ]
npm

Re: Chapter 8 problems -- Looking for

Reply Threaded More More options
Print post
Permalink
I'm definitely glad you wrote the book but it must be frustrating to see so much of it not apply after 6 short months.  I ran into the same thing when I was trying to learn about Rails.  :p
davidgolding

Re: Chapter 8 problems -- Looking for

Reply Threaded More More options
Print post
Permalink
The cost of doing business in an open source world :) If it brought people to an interest in Cake, and helped to strengthen the documentation (or, at least, helped to diminish the criticism that Cake didn't have enough documentation) then I consider it a success.

But for the readers, I still owe it to them to get up-to-date code samples and useful instructions. Just, so many hours in the day...
--Dave

Author, "Beginning CakePHP: From Novice to Professional"

[ get your copy at: http://www.amazon.com/Beginning-CakePHP-Novice-Professional/dp/1430209771/ ]