Cakephp Blog Tutorial Part 5 - Using the Save Method: Creating New Posts

Loading...

Sign in or sign up now!
Alert icon
Upgrade to the latest Flash Player for improved playback performance. Upgrade now or more info.
14,994
Loading...
Alert icon
Sign in or sign up now!
Alert icon

Uploaded by on Jun 6, 2010

In this Cakephp tutorial we cover how to create new posts for our blog. We use the models save method as well as a few other methods for sending flash messages and redirecting and we use the form helper for creating forms. You can download the source code at http://www.andrews-custom-web-design.com/cakephp.html

Category:

Science & Technology

Tags:

License:

Standard YouTube License

  • likes, 1 dislikes

Link to this comment:

Share to:

Uploader Comments (andrewperk)

  • hi andrew, i've been watching your videos because i have a school project, they are great but i have a question, you said you create form with the module for which you want the data to be saved, but let's say i want to show in the view the fileds for 2 diferent tables, and i guess i can't create 2 forms in the same view, do you have any advice fo a way to perform that? i hope i have explain myself, cheers.

  • @FPR You'll need to have associations set up between models (hasOne, hasMany, belongsTo). Post hasMany Comment. Your form will submit to Post model. In the form you access the other model using the input method but you include the model name with the field name like input('Comment.author'), this works for hasOne associations. If the model is a hasMany you access it like input('Comment.0.author'). In the post controller, instead of using save($this->data) use saveAll($this->data) instead.

  • @andrewperk i really appreciate that you took the time to answer me, i'll try what you said, let's see how it works, thank you. i have another question, do you know if there's a sort of book about cakephp, besides the "manual" that's on the cakephp page?

  • @FPR You should look up saving related data in the cake manual as you try to implement it. As for books, if you are on Cakephp 2 there are no books out yet. For Cakephp 1.3 Mariano Iglesias released a book, David Golding made a book back in 2008 its for 1.2 I believe. There's also a projects book but it's littered with errors. I found David Golding's book really good back when I got started, he explains the concepts well, but again its now out of date, most of it will probably work though.

  • @andrewperk In Cake2 you now use $this->request->data instead of $this->data in the controller. Helpers like the form helper should all be used like $this->Form->input(). In controllers we have methods to check what the requests are $this->request->is('post') || 'get' etc. Auth component doesn't auto hash passwords anymore. A $this->ModelName->exists() method to check if record exists and we can throw exceptions now with: throw new NotFoundException('errormessag­e') and others. Pretty good stuff.

  • @andrewperk Continuing on with some of the Cake2 changes that affect these videos are; All file names and folders use camecase or pascal case now. So in Cake2 folders are Controllers/ and Views/. File names should be PostsController.php instead of posts_controller.php. As well as it now is based on PHP5 and uses PHPUnit for testing instead of simple test. All properties should use proper identifiers now instead of var, use public private etc, same with methods.

  • @andrewperk I meant visibility not identifiers.

see all

All Comments (39)

Sign In or Sign Up now to post a comment!
  • Thanks so much man, your tutorials are amazing!

  • @andrewperk i thank you again andrew, please keep up the good work, the best of luck, if there is anything in where i can help you please feel free to ask.

  • @andrewperk why youtbe not allow me to post codes here? after i click on ok , it said ok, but nothing appear??/

Loading...

Alert icon
0 / 00Unsaved Playlist Return to active list
    1. Your queue is empty. Add videos to your queue using this button:
      or sign in to load a different list.
    Loading...Loading...Saving...
    • Clear all videos from this list
    • Learn more