skip to Main Content

Codeigniter 4 installed in sub-folder

CI seems to be looking at the sub-folder to use as the controller (using auto route – ie no routes), I even set up a route to try to direct the url to the correct controller but it still looks at the wrong url segment https://codeigniter4.github.io/userguide/incoming/routing.html#uri-segments

Ex: mywebsite.com/ci4app/home/participantlogin

Controller or its method is not found: AppControllersCi4app::home

CI thinks "ci4app" is the controller, it is really "home", it seems like I should just update a baseurl somewhere

Messed with .env, config file, .htaccess and apache config.

Folder Structures
/var/www/html/ – WordPress Site
/var/www/html/myapp – CI4

2

Answers


  1. Make sure the baseURL is set correctly. The sub-directory must appear in the baseURL (in .env file or app/Config/App.php). For example if CI is in a directory called ci4app, then the baseURL should be http://urltoserver/ci4app/

    For .htaccess modifications, this gist could be helpful.

    Login or Signup to reply.
  2. Check for CamelCase spellings… home should be Home <– Notice Capital "H"

    You also have a Capital "C"

    AppControllersCi4app::Home
    

    This should match exactly what you have in your controller, Example:

    class Home extends BaseController
    

    In your case it should look like this:

    AppControllersHome::ParticipantLogin
    

    And check your Route as well to ensure it is going to the right place:

    // Routes.php
    $routes->get('ci4app', 'AppControllersHome::ParticipantLogin');
    

    When someone types in domain.com/ci4app it will route internally to home Controller -> ParticipantLogin Method

    Good Luck, Happy Coding!

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search