Environment set up
- Use XAMPP to quickly set up the environment
- Download the package from CodeIgniter’s official website (latest version 3.1.9)
- Will download a zip file decompression was renamed ci_news, and placed in the C: / xampp/htdocs/dashboard/folder, such as the need to change to access the folder, please read the step 4, if don’t change, please read the step 5
- Change access configuration file in C: / xampp/apache/conf/HTTPD. Conf file, will be C: / xampp/htdocs custom address instead
- accesshttp://localhost/dashboard/ci_news/As shown in the figure, the framework is successfully constructed
Frame directory structure
PHP is the entry file, system is the framework code, and most of the edited code is written in the application folder. Models is the model file, views are the views, controllers are the controllers, and config is the configuration file.
Default access controller changes
The controller is accessed by default
$route['default_controller'] = 'welcome';
Copy the code
Instead of
$route['default_controller'] = 'index/home';
Copy the code
But visit http://localhost/dashboard/ci_news/ times 404, found that, after 3.1.4 version does not support such changes, Find the _set_default_controller method in the system/core/ router.php file
if(! file_exists(APPPATH.'controllers/'.$this->directory.ucfirst($class).'.php'))
{
This will trigger 404 later
return;
}
Copy the code
Change this paragraph to
if(! file_exists(APPPATH .'controllers/' . $this->directory . ucfirst($class) . '.php'))
{
$path_arr = explode('/', trim($this->default_controller, '/'));
$class = ucfirst($path_arr[1]);
$method = isset($path_arr[2])? $path_arr[2] :'index';
if (file_exists(APPPATH . 'controllers/' . $this->directory . $path_arr[0]. '/' . $class . '.php'))
{
$this->directory .= $path_arr[0]. '/'; }}Copy the code
To visit http://localhost/dashboard/ci_news/