CakePHP 3 Tutorial - part 2: Databases
Вставка
- Опубліковано 8 лют 2025
- ** UPDATED FOR CAKEPHP 4.0 **
• CakePHP 4 Tutorial - #...
SQL script for tables:
CREATE TABLE users (
id INT AUTO_INCREMENT PRIMARY KEY,
email VARCHAR(255) NOT NULL,
password VARCHAR(255) NOT NULL,
created DATETIME,
modified DATETIME
);
CREATE TABLE bookmarks (
id INT AUTO_INCREMENT PRIMARY KEY,
user_id INT NOT NULL,
title VARCHAR(50),
description TEXT,
url TEXT,
created DATETIME,
modified DATETIME,
FOREIGN KEY user_key (user_id) REFERENCES users(id)
);
CREATE TABLE tags (
id INT AUTO_INCREMENT PRIMARY KEY,
title VARCHAR(255),
created DATETIME,
modified DATETIME,
UNIQUE KEY (title)
);
CREATE TABLE bookmarks_tags (
bookmark_id INT NOT NULL,
tag_id INT NOT NULL,
PRIMARY KEY (bookmark_id, tag_id),
FOREIGN KEY tag_key(tag_id) REFERENCES tags(id),
FOREIGN KEY bookmark_key(bookmark_id) REFERENCES bookmarks(id)
);
------------------------------------------------------------------
Thanks so much for watching! Please comment, like or subscribe in order to support me. Also, please consider donating here:
jbjcode.com/don...
Donations are whats keeping me going, as the financial aid helps justify the amount of time spent + to buy new equipment for recording and editing.
Thank you!
/J.B.J.
This is so great to get back to cake after a longer brake and just 2.x experience! Cake 3 is sooo new and different... I am looking forwward to learn how it works now!
Thanks a lot for this! As a (even php) noob I have some serious trouble understanding the written tutorials on the official site. Your explanations made everything much clearer for me! I think your pace is just right and especially the thrown in explanations about basic structures and naming conventions are really helpful!
Keep them tutorials coming please! =)
Just two things (for other serious noobs out there ;D) -->
My editor can't do code completion with cake specific stuff and did not automatically add the "use Cake\Auth\DefaultPasswordHasher" on top of User.php. I did not notice the missing line first and had to add it manually. In the video the line just appears and is easy to miss ;).
Also I'm on Windows with XAMPP and I had to cd myself directly into the htdocs\bookmarker\bin folder and then do all the cake baking from there, without writing the "bin/" every time.
+Eve K Thanks a lot for compliments, and glad it works for you! Also thanks for the extra explanations for other people that might struggle with similar issues!
I will upload the next one soon, so keep an eye out on my channel! 1-2 days is the plan for the next upload, so stay tuned ;)
Thanks for watching
"This is powerful stuff" - You're a good teacher, haha. Cracking up at your speech conventions though!
Your tutorials are awesome man. Please make some more of Cakephp. I watched both of them and will watch the future tuts. thanks.
+sdasshuva Thanks a lot! I am sorry for the lack of uploads, but i have the next one planned very soon! So within a few days it should be up, so keep an eye out for my channel.
Thank you! Your tutorial was extremely useful in getting started the right way.
Awesome tutorial !!.. I got ver trouble while installing & using cake php. After watching your videos i made it very simple. Thanks alot man. Looking for more videos. :) ThumsUP
+Prasad Pyda Glad it helped :) I too had trouble installing at first, also one of the reasons i made the video :)
thumbs up to every tut so far
Thanks a lot for the tutorials! Very helpful. :)
ajajaja like you said at the end, i started this tutorial about 6 times to finally understand how to do things right, a lot of erros in my way XD so i thank you for this good video ;D
Thank you very much for your tutorial. Have a good time :D !
JB, since this is an MVC framework you may want to edit this video and let students know that they have to add this code here: use Cake\Auth\DefaultPasswordHasher; else they are going to get an error.
Thanks!
Useful tutorial. Can you bake a database view or can it just bake direct tables?
+Will B You can bake entire databases, but that just means it will "bake" all tables in that specific database.
+J.B.J. Programming Thanks - but can you bake views or just tables?
thank you very much!! very nice!!
very helpful
nice videos man, I have been using the framework for several years (2.x) now :), Im looking to learn what is new in the 3.0 version. thanks.
+Lenin Alevski Thanks for the comment mate! Let me know if you have suggestions for improving the way i do the videos :) If there is something in particular you like or dislike, or something you would like done different.
Thanks for watching! :) Next part will not be up before monday-tuesday next week due to holidays.
Thank you J.B.J!
Kindly share where is the routing for the /user or/bookmark is done when we do bin/cake bake all users or bin/cake bake all bookmarker
thanx alot dude, it was awesome . one question, when we bake how the page USERS created?
Thank you very much
Hey can you please make a video explaining the ORM to those of us that know cakephp 2? It's really difficult to know where things go now
hi i am new in cake php...... i installed it and set the database after that i am getting confuse .......dont know what to do ahead ......
the folders behviour, entity and table you talk about in 15:52 remain empty after filling the database. Did i miss something?
I am stuck in this error whenever I execute cake bake command.
Exception: Cannot use 'Bake\Shell\CommonOptionsTrait' for command 'common_options_trait' it is not a subclass of Cake\Console\Shell.
I could connect to the database, but failed with bin/cake bake all users.
error message is this.
[PDOException] SQLSTATE[HY000] [2054]
The server requested authentication method unknown to the client in /Applications/MAMP/htdocs/bookmarker/vendor/cakephp/cakephp/src/Database/Driver.php on line 92
Do you know what is the reason why bake command is not working well?
HI tutorial looks good , but how can i go to the console to check if it has connected to the database, thank you.
I can't using this command. How can you enable ext-intl for mamp pro in macos. Can you help me? Thanks
you may want to tell people they need to add this line of code at the top: use Cake\Auth\DefaultPasswordHasher;
at the top of what?
at the top of the user.php file
this tuto is amazing !! thank you so muuch
however why the name of the application is /bookmarks, in which step we named it ?
in the first video he gives this project the name 'bookmarks'. I only figured out by watching this video that we're making a bookmarked site/app;p
Any support or suggestions for connecting to SQL SERVER database ?? work in an enterprise setup with already established database. Would be really helpful to get to use sqlserver for my project. Thanks
Thank you so much for this tutorial and your hole series but every time i try to add or delete something, an error shows up " Undefiened type """ " didn't know what that does mean !!!! and i haven't been able to figuret out :\
I M CONFUSED VERSION 3 DOES NOT HAVE THE APP FOLDER SO HOW SHOULD I LEARN AND WHAT TO DO I M USING WINDOWS AND HAVE INSTALL CAKE VIA COMPOSER I HAVE CREATED THE DATABASE BUT DON'T KNOW WHAT TO DO AHEAD. i m not getting page like u with the url localhost/8765..
pls give some guidance
I did the exact same things as your codes, but I was not able to connect to SQL. Error message is this.
CakePHP is NOT able to connect to the database.
Connection to database could not be established: SQLSTATE[HY000] [2054] The server requested authentication method unknown to the client
Make sure you have the correct credentials for your local database (username and password) and that you have started a local testing environment (WAMP, MAMP, XAMP).
Sir, can you create a small project using cakephp 4?
I've using wndows 8. i dont understand where run following this command,"bin\cake bake all users" Plz mention this.thanks.
in the terminal you have to join(?) to the project folder. your path should look like this: ?:\wamp\www\project\ and you can use bin\cake.
hi..somebody please tell me how to get the the data that appear on 10.20?after we edit the the coding to connect
What software are you using to develop and edit?
He use PhpStorm.
Please tell setting the environment variable for windows10 and then bake all users etc
Parse error: syntax error, unexpected => (T_DOUBLE_ARROW), expecting ';' in /Applications/MAMP/htdocs/cakewalk/bookmarker/src/Model/Entity/User.php on line
what you should do,is coding manually controllers,models,and views,and explain each part.
+Host Vps Completely agree !!! I want to implement cakephp on a custom design and using cake bake for that really confuses me
+shibnath roy you are using a custom design, so just cake bake controller and model, and adjust your custom design with cakephp view
I get Error: BookmarkerController could not be found. when I open the site instead of getting what you got (the ability to enter rows into the database)
Oops. My fault. I went to the page matching my database name. I should have gone to the page matching the table name.
How can I add csv/excel file to update my database?
controller missing exception comes when i run m my baked table in local host what to do
i got this query but now it says database error
please, how to join many tables. (inner join in cake after baking)
Read up on cakephp associations. You can bake many-to-many associations but it is very important you have followed every convention, and even then it doesn't work very well. In my experience, the cake bake feature is only worth doing if you have a simple table you just want simple CRUD operations on it. If you go beyond that i find it best to implement from the ground-up
what's Earl?
How to use these commands in windows
bin/cake bake all users
bin/cake bake all bookmarks
bin/cake bake all tags
+moinuddin waheed To get the commands to work in windows I had to modify the system environment variable path to exactly where the cake, cake.bat and cake.php files where located on my system. For example, my location was at "C:\xampp\htdocs\cakephp". Once this was set I was able to run "cake bake all users" etc WITHOUT the bin/. Hope this helps.
I get an error it says DefaultPasswordHasher is not found.
+Kim Carlo Cortez i have the same error, could you find the solution?
+Kim Carlo Cortez
protected function _setPassword($password) {
if (strlen($password) > 0) {
return (new DefaultPasswordHasher)->hash($password);
}
}
+Kim Carlo Cortez try protected function _setPassword($value){
return sha1($value);
}
or return md5($value) or other password encryption, the way shown in the video didnt work for me either :P
you didn't add this line:
use Cake\Auth\DefaultPasswordHasher;
+cormac71 Thanks :) worked for me
Sir, where is the sql query
"Missing Controller"
Any idea why I get this error? I cannot open localhost:8765/xyz
+Vercevales Which controller is missing?
I've managed to fix that. I created the database on my own and I must have done it with mistakes because when I created it changing slightly your SQL script everything worked fine :)
hi i have this "Error:
The view for BookmarkController::index() was not found." how to I fix this?
which is the name of this text editor?
+Tropy Fast & Pinstripe Furious it is PHPStorm mate :)
top of the file/
use Cake\Auth\DefaultPasswordHasher;
function/
protected function _setPassword($value){
$hasher = new DefaultPasswordHasher();
return $hasher->hash($value);
}
More?
need more and more explanation,nothing new,all you do it's just reading what is in cakephp tutorial book,people needs basics and explanation to start with,and thanks for your efforts
+Host Vps Yes it is, that is what the tutorial is all about and i mention that in the first video - i make this series for people that doesn't like to read the material and would rather watch a video explaining it. The tutorial is also called "Bookmarker" which is the same name as the cake tutorial, so if you expected it to be anything other than that you haven't been paying attention mate :)
i thought it will be sth different than that, but thanks for your effort, great job :)
c'est intéressent mais les vidéos ne sont pas très claire
Bro i think using a windows laptop for your tutorials will be the right thing cuz many dont use Mac os #myopinion
Your intro is super cringe but the video is ok
i know, i have no idea what i was thinking lol xD thought about editing it out but now i just leave it there for giggles