thank you Quick Programing for php mvc from scratch videos is the best to learn php javascript and web development! Great teacher explaining all functionalities and provide the code of the lesson!
This is really great explaining and demonstrating. I understand much better how the models and queries are wired up now in an MVC / ORM. Really appreciate the work you put in to this.
Please people do not use this in World Wide Web before you know how to encrypt yor password. NO unencrypted passwords to database. Author should remember to say that to you. Be safe. Very nice tutorial, learned much.
Thank you very much for the lesson! Surprisingly, after watching a couple of videos on the same topic in my native language, I understood more from you! Watching and delving into the subtitles.
great content. you're teaching's really good. appreciate the zoom in/out, makes it easy to follow along and copy the codes afterwards. wanted to finish this in one go but got stuck for 2 days due to my assets files not being read. in case anyone come across the same problem where they can't load css/images/js just add the line before the last line in htaccess shown in the video: RewriteCond %{REQUEST_URI} !\.(css|jpg|jpeg|png|gif|ico)$ [NC]
Hi. This is a wonderful tutorial. If instead of writing all the PHP code at once, it would be great if HTML was developed along with it. Like if after creating the MVC structure, it was started from the HTML home page and all the changes related to login (necessary PHP on this page) were made. And then if any changes were required on the login html page they would be done there. And then the PHP code that needed to be written would be written by connecting the logging or home controller to it. And then gradually the complex code would be added, sequentially. Namespaces, triators and extra functionalities, such as validation rules, requests, posts etc, make this tutorial complex. It is quite difficult for beginners but probably intermediate learners will also find it difficult.
I implemented a router for the framework by modifying the app class and creating a router.php file. This was done because the app I am developing was becoming complex. I’d like to share my implementation and I hope you’ll do a tutorial for that soon. Keep up the good work 🎉
its good you're able to come up with your own implementation, that means you're actually learning and improving. There are many ways to implement the router so as long as it works as you need it, that awesome!
Great work. This OOP construct is awesome. I'll be watching your series on php photo gallery website next to learn how to implement the MVC Framework into a bigger project.
Happy to help! am glad you found it useful. Dont forget to also check the update where i added more functionality here ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-xgFPPT7-OqM.html
Fantastic, I really want this . Can not wait to watch this. Your your teachings are so great and the impacts it has created in me as a php developer is wonderful. keep it up man. Thank you Quick Programming.
Love it, but I would like to see how you can add in this MVC a shopping page and cart that is connected with a database and handle it from out the admin. I'm new in this and want to learn more on how you can build up from out that base MVC. Product must contain size, color and so on, because when you search for a shopping page with check out nobody use these settings during when you want to buy something you pick your size and color
Thank you for the awesome tutorial. a suggestions, add Request and Response Class, then a simple validation class, You will have a beautiful MVC framework that work as a base for all small websites and APIs hence Response Class. Nevertheless, Great tutorial.
Thanks for the suggestions. i'll be making a follow up tutorial to add more functionality soon. a request class and validation class will be included and a few more classes to speed things up
The routing is fine but it is how Codeigniter does it. Laravel does it differently and is more robust cause you can clearly define the request method and map the appropriate controller method. With codeigniter example your can’t tell if its a get, post, patch etc without doing additional check. Anyway, it’s good if you are just beginner learning how it works as this is one way to do it.
in this you can also specify the method because the second item is the method, e.g in this link, 'edit' is the method 'website.com/product/edit'. laravel is too complex for no reason. code igniter is slightly less complex, so i prefer it. Sure laravel can specify if its a GET or POST request but whats the real world application of that? it just creates a lot of 'page not found' scenarios. better to check using the request class or server method. The complexity of laravel is what i try to avoid by creating my own framework. if i copy laravel exactly then its better i just use laravel because it already exists. i could save time. in the end its all about preference i guess, i prefer making things myself, that way am not lost when a clients wants to change anything
i didn't finish the video yet, but just, at 20:12 it's a bad idea to indicate the directory of your admin files in here, in terms of security, because it makes it very easy for hackers to know where to search for your backoffice! you can instead: - ask google not to index these pages from google search central - add php headers at the beginning of your files: header("X-Robots-Tag: noindex", true); - add a meta tag in your html:
thanks it was great. better to replace a silent keyboard and mouse, get prepared for the course. You have been copying/moving/making changes/forgot your code back-and-forth many times.
Am a busy person. I don't have the time to prepare for a course. I code in real time. The back and forth is important because it shows you how coding is like in the real world, rather than showing a perfect version which never happens in real life. However, there are plenty of shorter and well peppered videos online, so you don't have to watch mine
hello quick i need your advice i have learned [ html - css - php - mysql - basics of ajax - api - laravel ] what aslo i need to learn to be backend developer and i am junior by the way and what is the next steps to be pro from your opinion ❤❤❤❤
to become a pro, learn OOP. after that, all you need is actual experience. start building actual websites. ask people who need websites if you can build them one for free. even friends and family if possible. the experience you get from it is invaluable. you can then use those same websites as part of your portfolio when looking for work. people care more about your work experience
Hi, I find this tutorial absolutely priceless. It's got my thumbs up! (see my reply below. it was an easy fix due to my error) Everything worked out fine until I got to 2 hours and 7 mins. It's definitely not a criticism but I have to point out that the return query doesn't work for me, it throws an error. This is the error message. Fatal error: Uncaught Error: Call to undefined method Model::query(). I'm pretty newbie so I am not sure why you don't get the error but I do. I have checked the syntax line by line and it's identical and it ran fine up to the echo() of the query, but not with the code changes that followed including the return of the query. Any input would be appreciated.
the error is saying you dont have a function called 'query' in your model class. This could be because you're not including or extending the database class inside your model. SO make sure you have the parts the 'extends database' in your model declaration. e.g class Model extends Database{ Or it could be a spelling error. Make sure the function in the database class is exactly named 'query' and not something else.
@@QuickProgramming since you gave you those suggestions it helped me question if I had done something wrong. I checked back over the video slowly from around 1 hour 40 mins. It turns out that at 1 hour 47 mins, because you cut and paste the function query() between the core files model.php and the database.php and back again, that I forgot to paste the public function query() back into Trait Database {} in database.php. It's definitely given me experience of understanding the code better. Thanks again for your time in giving me direction.
@@QuickProgramming Thanks again.. debugging definitely draws my attention to the details. I suspect i'll continue to get more bugs as I continue to create errors in the syntax also :) I just wish I was at the same level of creativity as you and have knowledge of the functions like you do!
Thanks for these great tutorials, I believe you are one of the best on youtube. Do you have an Udemy channel, please? just for follow on complete production applications.
Since the protected variables were declared in the trait Model, how do you overwrite them when using the trait model in another model (my model) using trait Model? would you use the constructor? the variables must be the same as the trait, but I want to change the variables based on the table from the database I am querying? I hope that makes sense what I am asking.
This is amazing brother, but I encounter a problem here, I am using a live server, php -S localhost:8888, and when I run print_r($_GET), I get an empty array, could you help me with that, please.
Hello Eathorne, There is one thing I dont understand about model. When we execute the statement we give a array to execute() function. And now: For example the prepaired query is: SELECT * FROM users where id = :id for execution we give information that [ 'id' =>4] - there is no expressions ":id" (with a colon). How does the computer know that it should associate ":id" with "id"? W bindValue we should use (':id' , $x =4)...
@@QuickProgramming Unfortunately, I still don't understand :( does this mean that the computer will look for the most similar key? It doesn't have to be identical? Does prefixing the key with a colon have any meaning here?
You are the best teacher when it comes to coding for sure!! I was wondering how would we go about templating when we have the same header and footer used on all pages without copying them on every page... Where would we use them? Would it be the index page, or would we create something else that gets pulled before and after each view?
thanks. you can load any view file, including the header if you save it as a separate file and then load it the same way you load other view files inside another view, e.g $this->view('header'); i made a simple social website using this framework here. you can get some ideas from there. this is a link to all related videos, but you can just watch the one with the social website for your issue. ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-Hsph_-1EbPA.html&pp=gAQBiAQB
@@QuickProgramming Thank you for a prompt reply! - I am working on a platform and would like to use your MVC instead of procedural PHP as usual. Appreciate all your hard work, as I learn a lot from you!
Your framework router logic looks like the CakePHP routing logic. The first segment of the incoming request should match with a name of a controller class. It's a little weird for me
Great tutorial. It really helps me. I really hate PHP, but in the same time I understand how cool is this language. Following this tutorial, it were many mistakes, and all of them was because I made mistakes in some name of variables (lost concentration I guess). Now I have an issue with inserting new user in the table. When I use show($_POST) it shows me the inputs, but freaking $user->insert($_POST) does not! What is the problem?
The problem is in terms actually. Accepting the terms is part of validate function. And after you put check mark to Accept the term it's value becomes the part of what you try to post. But there is no terms column in users table. If I remove accept the terms from validate function it works. But I don't understand why is it worked for you, man ?
Greetings to you my PHP hero, and greetings to everyone committed to this unique discussion thread. Please sir, can this MVC be used for public production???
I had a general error when attempting to Insert or update around the 2 hour mark in the video. Changing the line in Database.php if(check) to if(check > 1) fixed it. I dont know if anyone else had the same problem.
good question. the get_row function is for running a query, first function uses an array instead. using the first function you dont need to specify a table or even type a query. but there are times when you need to run a complex query and need only one result, thats when you use the get_row function
Thanks for the video, you are a great teacher, can I ask if it's possible to send data with Ajax from login page to controller Login in this MVC ? I have tried, but failed.
sure its possible. the code below will send data to the controller of whatever page you're on. let xhr = new XMLHttpRequest(); xhr.addEventListener('readystatechange',function(e){ if(xhr.readyState == 4 && xhr.status == 200) { alert(xhr.responseText); } }); xhr.open('post','',true); xhr.send(); to send to a specific controller, add the full path to that controller in the open part like this: xhr.open('post','/home',true); ROOT represents the absolute http path to your project, e.g localhost/mvc/public
@@QuickProgramming I get a way to pass the ajax Post variables to the controller page, however, when trying to instant the Class I receive a error: Class "Login" not found in C: \xampp\htdocs\MVC\app\controllers\Login.php:12
MVC may be simple and popular but has code exposed to the public found in every controller. It is also not dynamically created. A better system is where there is one controller that is called and altered in the background by separate code not on the controller but held in a different place. Connections to dbases being modular. Write the code once and use it as requested. Each time a visitor comes to a webpage (controller), they are actually visiting the same page and it has been recalled and adapted according to the url, the connections required and security rights being satisfied. So no matter how a website or code is accessed the security of the code itself, not just the controller, is in place, with all code invisible and all code under tight security.
You use include if the file you want to include is optional. Include will throw a warning if the file is not found but the code will continue executing. When you use require, the code stops executing when the file is not found. It throws a fatal error. I prefer require in this case so the cod doesn't continue if the file inst found. You can use include if it suits your purpose better. It's just a matter of preference
i dont know why im getting a 0 value for the array with empty value, also $_GET['url'] didnt worked for me i had to use $_SERVER['REQUEST_URI'] did this things changed with php 8?
Hello to everyone. Please solve my problem. When we make a page named about-us then show page not found. Already create about-us.view.php page and Aboutus.php controller. Plz help me
For example I have allowedColumns array and I found the issue for example if I insert user I need "created" and when I update I need "modified" but never both together. Does this mean I have to create a new protected variable ?
Thanks for the guide. It's really very easy to understand, good work! I just have a question about the public directory. What is the best way to implement it so that it is no longer indicated in the URL? So that you only see your domain. Many thanks in advance!
the public folder never shows up on the live server. its just there to organise your files better on your local machine. on a live server, you will be given a public folder there as well to put your files. thats where you will add the files that are in your local public folder too
@@QuickProgramming Ahh okay, thank you for your response! You said in your video that it is not possible to load JS files inside the app folder. Couldn't this be used within the view Pages: So the script is inserted as JS content within the head area. Maybe they is a better way to insert the JS file for each view page over the controller class? So you don't need to put the script tag on each view page.
@@user-xv4fb5wz9i yes you can load JS & CSS that way but its inefficient. the reason we load JS & CSS files using the tags is because a user's browser can store them locally. This means they only need to be loaded once on the first page load. This is known as caching. loading the js as part of the HTML adds bulk to the code being loaded on every request. furthermore, you cant do this for images since you can use the require or include on them. you'll still need to put them in the public folder. so why not just put your JS and CSS files in there too? i just dont see the point of trying to hide JS files when the user can still see the JS code no matter how its being loaded
@@QuickProgramming Thank you for your extensive answer! You are right that JS code is usually always used for client-side rendering. I understand why you used this folder structure for the software. My message does not aim to be more critical of this. I'm just testing what I can do with PHP and vanilla JS to make my JS code less readable. I already use techniques like obfuscation and minification. In the future I would like to further limit access to the code by running the code on the server and the client only holding the resulting HTML code. Like this example: Restricted Access Click me
i want to write SELECT * FROM users WHERE id = 1 id != 2. How can i modifiy where method inside model class ? its not working when i pass $model->where([id=1],[id=2]). Because array_marge replace delicate key. video Timeline 2:07:23
i think you forgot the '&&' like this: SELECT * FROM users WHERE id = 1 && id != 2. but this query doesnt make much sense because if id is 1 then its not 2, this means there is no need for the last part of the query which says 'id != 2'
@@QuickProgramming Thanks for the reply. Really appreciate. actually, i try to build SQL with an "OR" operation like you. like SELECT * FROM users WHERE name = 'A' or name = 'B". $data_or = ['name' => 'A', 'name'=>'B'] $data_or showing only ['name'=>' B'] as an associative array can not contain duplicate key. any idea how to build this SQL like you? so far my code if (!empty($dataOr) && isset($dataOr)) { $this->sql .= '('; foreach ($dataOr as $key => $value) { $this->sql .= $key . ' = ? OR '; array_push($this->val, $value); } $this->sql = rtrim($this->sql, ' OR '); $this->sql .= ')';
you can use data validation to avoid that. then run the insert method only after checking if values are unique. i made a tutorial on form validation here ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-ymPlbgz6BoU.html
unset is used to remove all keys from the array that are not found in the database table or the ones you dont want to allow edits. if you remove unset, the function will create a query that has columns that dont exist in the table and so your query will not run. e.g if you have a user signup page, you will have the following fields: username, email, password, retype_password, accept_terms_and_conditions. but your database table will have only these columns: username, email, password. so when you do this: $user->insert($_POST); the function will create a query that includes all fields from your form. this query will not work because it contains "retype_password" and "accept_terms_and_conditions". the unset part will remove these columns that dont exist in your table. you can also use this to make sure some columns are never edited, e.g the id column or date_created column. the unset part can remove these columns for you automatically from the query. watch this video where i use the framework to make a website ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-Hsph_-1EbPA.html
the controller is required to load the view, so you cant have a page without a controller, unless you change the framework to accommodate that part. But its a waste of time to add extra code just to fix one page issue. Its just better to have an empty controller. less code, better performance
I am going to build a web portal for our company and I don't want to use any existing php framework. Can I follow this tutorial and use this framework as my reference or structures for our company web portal?
Yes, that's what it's for. I use this too for my own websites. That way you understand every line of code and so fan easily change anything and add new features as you wish