14. PHP autoload and php use namespace | Page edit | CMS OOP tutorial MVC

แชร์
ฝัง
  • เผยแพร่เมื่อ 20 มิ.ย. 2024
  • Let's use php autoloader and how PHP use namespaces in this mini php namespaces tutorial. We will see how to include files automatically in a project, and also how namespaces can allow us to have multiple classes with same name, and how autoloading can figure out where to find our files.
    Interested in learning real-life PHP design patterns?
    ➡️ www.ApplicableProgramming.com/
    If you are interested in programming courses related to web, please visit www.applicableprogramming.com/ to view courses where we show the problem, then we try to solve it the hard way, and then we show how we can benefit from proven solutions.
    ➤ LINKS
    ➡️ Source on github: github.com/applicable-program...
    (use tags to navigate between lessons)
    ➡️ getcomposer.org/ package manager
    ➡️ Private "Applicable Programmers" facebook group / applicableprogrammers
    ➡️ Discord server / discord
    ➡️ Other tutorials: www.ApplicableProgramming.com
    Timestamps:
    Intro (00:00)
    CMS page edit (00:45)
    Namespaces - explanation (17:49)
    Namespaces - practical solution (22:47)
    Homework (31:25)
    Summary (33:33)

ความคิดเห็น • 44

  • @arunkumark1596
    @arunkumark1596 2 ปีที่แล้ว +3

    Because of tutorial i was able to understand namespace and autoloading. Thanks a lot for your tutorial.

  • @raku472
    @raku472 3 ปีที่แล้ว +3

    Finally understood namespace. Thanks a lot.

    • @ApplicableProgramming
      @ApplicableProgramming  3 ปีที่แล้ว +1

      Thanks for letting me know Ranjeet. It is comments like this that makes it all worth the effort and time to make these videos!
      So... your comment and support is appreciated sir! :)

  • @jobayertuser
    @jobayertuser 2 ปีที่แล้ว +1

    Sir thank you really appreciate you effort

    • @ApplicableProgramming
      @ApplicableProgramming  2 ปีที่แล้ว

      Thank you Jobayer, glad you liked it. Are you following the entire tutorial?

  • @hochihuynh2024
    @hochihuynh2024 ปีที่แล้ว +1

    Great. Thanks! I'm looking for the way to create relationship between 2 tables in PHP MVC.

    • @ApplicableProgramming
      @ApplicableProgramming  ปีที่แล้ว +1

      That is great thing to do. You can of course do that in multiple ways, but in essence you need to keep track of relations between objects, and then adapt query builders so that they can join relations.
      Easy in theory, but there is a bit of coding. I've done that in the past once, and... It worked, but I did switch to the of the shelf solution for ORM, because it was just waaay more powerful, and way better tested. You will get into a lot of troubles along the way, that many others have already successfully solved already.
      But of course, you know best what you need. If nothing else, it is a great exercise and learning opportunity.

    • @hochihuynh2024
      @hochihuynh2024 ปีที่แล้ว +1

      @@ApplicableProgramming ORM is the best. Which ORM do you suggest for a beginner?

    • @ApplicableProgramming
      @ApplicableProgramming  ปีที่แล้ว

      @@hochihuynh2024 Ahhh... great question. To be honest, its been a looong time since I used some of ORMs that were not a part of the framework. If you are using Laravel, then use the one that comes with it. I would say Doctrine is good, but... learning curve is quite steep. It is not just plug and play, especially when things start getting complex. You might risk becoming the "master of workaround" while using it.
      I guess you can try a few and see how it goes, not sure to be honest..

  • @3266711732665514
    @3266711732665514 2 ปีที่แล้ว +2

    I like your voice, keep up the good work man! 👍

    • @ApplicableProgramming
      @ApplicableProgramming  2 ปีที่แล้ว

      That is very kind to hear Lucas, thank you :) Have you been following the entire tutorial?

    • @3266711732665514
      @3266711732665514 2 ปีที่แล้ว +1

      @@ApplicableProgramming I'm in the beginning still, just came here to see where this is heading for, liked what I found!

    • @ApplicableProgramming
      @ApplicableProgramming  2 ปีที่แล้ว +1

      @@3266711732665514 welcome then, I hope you will like it. Ask any questions you might have on the way, and happy coding :)

    • @3266711732665514
      @3266711732665514 2 ปีที่แล้ว +1

      @@ApplicableProgramming Thanks, God bless you!

    • @ApplicableProgramming
      @ApplicableProgramming  2 ปีที่แล้ว +1

      @@3266711732665514 if I may ask, are you already working as programmer, or still learning?

  • @luizmeier
    @luizmeier 2 ปีที่แล้ว +2

    I prefer the short video format with smaller examples rather than presenting this in a CMS (which I don't follow) as an example. I expected the use of Composer. Your videos are good, I'm giving my opinion because it was asked in the minute: 24:53

    • @ApplicableProgramming
      @ApplicableProgramming  2 ปีที่แล้ว +1

      Thanks Luiz, that is a good point. I will think more about shorter "to the point" videos. Do you have some examples of what you would like to see?

    • @luizmeier
      @luizmeier 2 ปีที่แล้ว +1

      @@ApplicableProgramming I made (yesterday) a solution to the challenge of a job. In it, I use Composer with autoload. It is a challenge to make an ATM machine. I used closures (two) exactly as you demonstrate in the last video (PHP Design Patterns in REAL life) (The code is in PHP and in Portuguese (but you can understand the code, naturally) and with unit tests. If you have interest and time to see the repository (very small size), please tell me a way to send you the github link. I can't make it public because the process is in progress. After the company's evaluation process, I can make it public. Feel free to comment or use it as a review code demo if you find it interesting. All criticism is welcome.

    • @ApplicableProgramming
      @ApplicableProgramming  2 ปีที่แล้ว +1

      @@luizmeier Sounds great, I would love that! I think those types of videos help others a lot to see how to use a bit advanced concepts in real life.
      Do you have facebook or discord? If so the links are here on top right of the banner th-cam.com/users/applicableprogramming
      If not you can just subscribe to course notifications on www.applicableprogramming.com and you will get my email. If neither of those works, I can give you some links directly so just let me know.

    • @luizmeier
      @luizmeier 2 ปีที่แล้ว

      @@ApplicableProgramming Just sent the link in your Support page at www.applicableprogramming.com . Thank you for your replies.

  • @1stimpressiondental174
    @1stimpressiondental174 2 ปีที่แล้ว +1

    Hi, Thank you for the video. I am developing a good understanding of OOP when it is done correctly, but these videos are a bit too advanced for me. I was wondering if you could have a series w a simpler app that is geared toward beginners. Thank you

    • @ApplicableProgramming
      @ApplicableProgramming  2 ปีที่แล้ว +1

      That is an excellent suggestion. I have started on the tutorial for absolute beginners, but it could take some time before it is finished as I want to cover a lot of topics there.
      What are you struggling with the most?

    • @1stimpressiondental174
      @1stimpressiondental174 2 ปีที่แล้ว

      @@ApplicableProgramming I think the connection between classes is a little hard to follow. For example, it took me a while to realize how the page is displayed and what the Template class actually does. I know it is intuitive for a seasoned developer, but for someone who is just seeing it, it would be easier to understand it if a big picture of why we need a class and where we need it would be helpful. For example, the Template class puts together 3 components of the page, which are the overall layout w the help of the controllers, the module w the help of the router, and the variables w the help of the entities.
      I guess it is hard for me to follow the thought process behind creating some classes. If the purpose of the classes is explained before their creation, and a less complex app that requires fewer number of classes would help beginners.
      One more thing that is confusing to me is how some variables are set from being hardcoded to a dynamic structure using the foreach loops. I understand the concept when I see it, but I do not think I would be able to come up with it.

    • @ApplicableProgramming
      @ApplicableProgramming  2 ปีที่แล้ว

      @@1stimpressiondental174 This is excellent input, thanks for elaborating. Have you been following the entire CMS series or only this video?

    • @1stimpressiondental174
      @1stimpressiondental174 2 ปีที่แล้ว +1

      @@ApplicableProgramming I have followed the series and coded along to this point.

    • @1stimpressiondental174
      @1stimpressiondental174 2 ปีที่แล้ว +1

      @@ApplicableProgramming by the way, I love the homeworks because it makes you think it through before you see the code, so you realize what is missing and then when you see the code it makes more sense.

  • @1stimpressiondental174
    @1stimpressiondental174 2 ปีที่แล้ว +1

    I do have a question about our setValue() function. As I understand, hardcoding and duplicating code is the enemy. On our setValue() function, why do we not use the following format,
    public function setValues($object, $db_data) {
    foreach ($db_data as $field_name => $field_value ) {
    $object->$field_name = $field_value;
    }
    The field names are exactly the same as field names on our database, so why not just take those from the DB instead of hardcoding them under each entity class?

    • @ApplicableProgramming
      @ApplicableProgramming  2 ปีที่แล้ว +1

      That is a very good question, and that is one way of doing things. That is how Laravel does it, it completely relies on you setting the proper properties so it is very loose on the definitions. And that works just fine.
      Symfony/doctrine on the other hand is on the opposite side of looseness spectrum, and it requires you defining fields and their types and pretty much everything.
      I personally am a fan of the Symfony way of doing it, so this attempt is something in between, just because it helps me with development, I can easily see field names from editor without having to open a database. It also makes relations between objects a bit easier and more defined as they are not completely dynamic like in Laravel. For my personal taste, it is just too much magic when properties are completely dynamic, so I like a bit more control.
      But in essence it is a personal preference, so you can do it one way or the other, or even combine both.
      If you look at the newest video in the series, you can see one place where I use these fields to figure out what is the ID and build the query that way. th-cam.com/video/fw2yJXmTdsg/w-d-xo.html

  • @taranewstime6909
    @taranewstime6909 2 ปีที่แล้ว +2

    Sir when next video will come

    • @ApplicableProgramming
      @ApplicableProgramming  2 ปีที่แล้ว +1

      It will take some time, but what you can do while you are waiting, is to start this entire project from the beginning but without looking at the source, and try to recall as much as you can about the concepts described here

    • @taranewstime6909
      @taranewstime6909 2 ปีที่แล้ว

      @@ApplicableProgramming thank you for your reply sir

  • @msq7521
    @msq7521 2 ปีที่แล้ว +1

    it is very unfortunate that every episode comes after a long time

    • @ApplicableProgramming
      @ApplicableProgramming  2 ปีที่แล้ว

      I agree, that is true... I try, but... yeah... It takes about 20-30 hours to make one episode, practically 7-8 days of work in a row every evening (without life getting in between).
      Otherwise quality would have to suffer, and I do not think that is a good idea.
      However, a lot of students go back, start a new project and try to code it from memory, and see what they have remembered from the course. Then make a variation of the project, because realistically, this project is in full speed now, it is just to duplicate what was discussed on other modules and continue with the CMS.
      Btw, what would you like to see discussed next?

  • @tpssshubham9047
    @tpssshubham9047 ปีที่แล้ว +1

    Is this series completed or not?

    • @ApplicableProgramming
      @ApplicableProgramming  ปีที่แล้ว

      Good question. The project is never finished - always ready!
      I will not close the doors on the project, but I think it shows a lot of concepts and gives a good starting point on expanding the CMS on your own. One day a new lesson will probably come, but what a lot of students do while they are waiting, is to start this entire project from the beginning but without looking at the source, and try to recall as much as you can about the concepts described here. To really be sure you understood what you was watching

    • @tpssshubham9047
      @tpssshubham9047 ปีที่แล้ว

      @@ApplicableProgramming Thanks for your reply