CodeIgniter 4 from Scratch - #5 - Routes

Поделиться
HTML-код
  • Опубликовано: 24 дек 2024

Комментарии •

  • @ajaysinghchauhan1021
    @ajaysinghchauhan1021 4 года назад +3

    thank for uploading these nice video

  • @josechirino5168
    @josechirino5168 4 года назад +3

    Great video, everything well explained. Thanks

  • @otmanm4095
    @otmanm4095 4 года назад +1

    You great, thanks !!

  • @laurentiuudrea1743
    @laurentiuudrea1743 4 года назад +1

    Hello! I have a little question. When we need to use "routes->add" and when we need use routes->get"? Oh... later in video I get the answer :)

  • @SilverBlaidd
    @SilverBlaidd 4 года назад +1

    Will you talk about multilingual apps in the future? I wonder what is the proper way of routing that in CodeIgniter 4.

    • @AlexLancer
      @AlexLancer  4 года назад +1

      SilverBlaidd, actually yes I want to create a video on that in later episodes and will show how to create a routing also

  • @Regzcastro
    @Regzcastro 4 года назад

    i have a problem with the public in the url.. my form actions and css/js link cannot be found if i do not include in the source url "public". how do i get about this?

  • @MrKeebee
    @MrKeebee 2 года назад

    Hi Alex, great tutorial! Could you show us the delete method too? I have an issue 'page not found' when I use $routes->delete('blog/(:num)', 'Admin\Blog::delete/$1)... :-(

  • @chaker7778
    @chaker7778 4 года назад

    thanks Alex .... so what the diffirent between add and get in the route file

    • @AlexLancer
      @AlexLancer  4 года назад

      ->get will work only for GET requests. But if you will submit a form with POST method on that same url, ->get route will not be triggered

  • @DIPTIMOYMANDAL
    @DIPTIMOYMANDAL 3 года назад

    I have a qestion , this not working $routes->get('blog/new','Admin/Blog::createNew'); giving 404 error and Controller method is not found: new but this works $routes->get('blog/createNew','Admin/Blog::createNew'); giving the form as output

    • @prithvituladhar6938
      @prithvituladhar6938 3 года назад

      it should be $routes->get('blog/new', 'Admin\Blog::createNew''); with backward slash

  • @claralugtu5184
    @claralugtu5184 4 года назад

    Hi Alex, after I submitted the post form it displays object not found. I'm stuck here. can you help me?

    • @AlexLancer
      @AlexLancer  4 года назад

      Hey, Clara, it is tough to answer if i can't see the code.
      Therefore, pls upload it on github and let me know so that I can check it.

  • @ndoch1
    @ndoch1 4 года назад

    Nice tutorial Alex! But do we have to add routes for every method that we have?

    • @AlexLancer
      @AlexLancer  4 года назад +1

      No, there is "auto routing" that works like this: domain.com/controller/method

    • @ndoch1
      @ndoch1 4 года назад

      @@AlexLancer so when exactly do we need to specify it?

    • @AlexLancer
      @AlexLancer  4 года назад +5

      @@ndoch1 1. You can disable default routing and create only your own specific rules. 2. When you want to overwrite the default rules. Ex: instead of domain.com/shop/product/laptop-hp you want to make it domain.com/product/laptop-hp
      3. When you want a route for GET request to be different from POST request. Let's say you have a form domain.com/form, and when it is submitted you want to handle the validation in different method but still the same url.
      Hope that helps :)

  • @josechirino5168
    @josechirino5168 4 года назад

    Hi bro, please look at this problem I have ...
    When I use placeholer in the routes for sub-folder it doesn't work:
    $routes->get('cerrar-jornada/(:any)', 'admin/Jornada::cerrarJornada/$1');
    respond with>>>//404 - File Not Found
    //Controller or its method is not found: \App\Controllers\admin::index
    this work:
    $routes->get('cerrar-jornada', 'admin/Jornada::cerrarJornada');

    • @AlexLancer
      @AlexLancer  4 года назад

      Jose, If you still did not find the solution, please upload your code to github so that I can see all the files

    • @josechirino5168
      @josechirino5168 4 года назад

      @@AlexLancer
      github.com/nacio1/polla3x2
      there is the app folder
      same problem: forum.codeigniter.com/thread-76736-post-376929.html#pid376929
      I try using back slash and now the method work->$routes->get('cerrar-jornada/(:any)', 'admin\Jornada::cerrarJornada/$1');
      but it returns with 404 error with this in the url :
      localhost/admin/cerrarjornada/jornada/jornada/jornada/jornada/jornada/jornada/jornada/jornada/jornada/jornada/jornada/jornada/jornada/index

    • @josechirino5168
      @josechirino5168 4 года назад

      @@AlexLancer Now works, it was an error with the redirect function. Thanks for answering

      and please continue with the content

  • @jigglypotatoes
    @jigglypotatoes 4 года назад +1

    Hi, Alex great tutorial. One question regarding controllers. You seem to be creating controllers by duplicating default one and that uses App\Controllers\BaseController, in the docs however they tell you to create controller using App\Controllers\Controller what is the difference if any?

    • @AlexLancer
      @AlexLancer  4 года назад +9

      Hey Bartlomiej, good question!
      You can use BaseController to preload helpers, libraries, models etc. that you are using in other controllers, so that you don't have to write all the common files that you have over and over.
      So let's say you have a UserModel.php that you will use in all (or almost all) of your controllers
      Now you can go inside BaseController and load it there and store it in a variable, let's say protected $userModel;
      $this->userModel = new UserModel().
      No every controller that extends BaseController has this property available just by typing $this->userModel
      So the point here is, it is not required to extend the BaseController, but if you have controllers that use similar libraries (and other files), you can use BaseController (or create other Controllers that you need based on your logic) to preload all the stuff.
      Hope that helps!!!

    • @jigglypotatoes
      @jigglypotatoes 4 года назад +2

      @@AlexLancer Yes it does! I see the difference clearly now.

  • @tripmaster2840
    @tripmaster2840 3 года назад

    Thanks

  • @chaker7778
    @chaker7778 3 года назад

    thanks so much bro

  • @wiwisona81
    @wiwisona81 3 года назад

    I got this error "Controller or its method is not found: \App\Controllers\AdminBlog::index"

    • @yuan3234
      @yuan3234 3 года назад

      Same issue here

    • @prithvituladhar6938
      @prithvituladhar6938 3 года назад

      If controller is inside Admin folder syntax should be Admin\Blog::index..

  • @radybmcs6516
    @radybmcs6516 4 года назад

    I got the problem with default value of function:
    - My controller:
    public function teaching($subject = "CI4") {
    return "I am teaching : " . $subject;
    }
    - My routes
    $routes->add('teach/(:any)', 'Teacher::teaching/$1')
    It fine if I pass the parameter localhost:8080/teach/ci4
    but it will error when i don't pass the parameter localhost:8080/teach

    • @AlexLancer
      @AlexLancer  4 года назад +2

      add second rule without (:any)
      $routes->add('teach/(:any)', 'Teacher::teaching/$1')
      $routes->add('teach', 'Teacher::teaching')

    • @radybmcs6516
      @radybmcs6516 4 года назад +1

      @@AlexLancer Thank you so much !

  • @kotakukepri2892
    @kotakukepri2892 3 года назад

    keren

  • @satishksharma
    @satishksharma 4 года назад

    I like your tutorial but problem is text size so I request please make video tutorial with caring of mobile users.