Cakephp Blog Tutorial Part 5 - Using the Save Method: Creating New Posts
Loading...
14,994
Loading...
Uploader Comments (andrewperk)
see all
Video Responses
This video is a response to Cakephp Blog Tutorial Part 4 - Using the Read and Html Link Methods
see all
All Comments (39)
-
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...
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 4 months ago
@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 4 months ago
@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 4 months ago
@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 4 months ago
@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('errormessage') and others. Pretty good stuff.
andrewperk 4 months ago
@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 4 months ago
@andrewperk I meant visibility not identifiers.
andrewperk 4 months ago