-1

I'm try to moving some website from CI 2.x to CI 3.1.2, but after I moving my old website to new CI I get 404 error when I'm access that page.

this is my CI structure :

Applications
- controller
-- back
-- front
--- Home.php

- libraries
-- front.php

- model
-- home_models.php

- views
-- back
-- front
--- elems
---- head.php
---- foot.php
--- pages
---- home.php
--- display
---- pages.php

Controller Home.php

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Home extends CI_Controller {
    var $data;

    public function __construct(){
        parent::__construct();
    }

    public function index(){
    $data = array();
        $this->front->pages('home',$data);
    }
}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */

Libraries front.php

<?php
    class Front {

        protected $_ci;

        function __construct(){
            $this->_ci = &get_instance();
        }

        function pages($page, $data=null){
            $data['head'] = $this->_ci->load->view('front/elems/head', $data, TRUE);
            $data['content'] = $this->_ci->load->view('front/pages/'.$page, $data, TRUE);
            $data['foot'] = $this->_ci->load->view('front/elems/foot', $data, TRUE);
            $this->_ci->load->view('front/display/pages', $data);
        }
    }

?>

in my route :

$route['default_controller'] = 'front/home';

and in my autoload :

$autoload['libraries'] = array('front');

In old CI that's structure is work, but after I'm trying to implement that structure in 3.1.2 I can't access that page. What's wrong with this.

Sparky
  • 98,165
  • 25
  • 199
  • 285
  • Did you follow the upgrade guide? https://www.codeigniter.com/user_guide/installation/upgrade_300.html – Sparky Jan 19 '17 at 20:30
  • Your default controller cannot be in sub folders. –  Jan 20 '17 at 02:05
  • if I want default controller in sub folder. What should I do? @wolfgang1983 – Farhan Afandi Jan 20 '17 at 05:40
  • @FarhanAfandi use my application / core / MY_Router.php extension https://github.com/wolfgang1983/CI3-default_controller_route_with_sub_folder/tree/master/application/core –  Jan 20 '17 at 05:49

2 Answers2

0

Read Upgrading from 2.2.x to 3.0.x

  1. Update your CodeIgniter files
  2. Update your classes file names
  3. Replace config/mimes.php
  4. Remove $autoload[‘core’] from your config/autoload.php
  5. Update Database and Routes files.
  6. etc ....
Abdulla Nilam
  • 36,589
  • 17
  • 64
  • 85
0

I found this way

Change my system core Router.php into

protected function _set_default_controller()
    {
        if (empty($this->default_controller))
        {
            show_error('Unable to determine what should be displayed. A default route has not been specified in the routing file.');
        }

        // Is the method being specified?
        if (!sscanf($this->default_controller, '%[^/]/%[^/]/%s', $directory, $class, $method) !== 2)
        {
            $method = 'index';
        }

        if ( ! file_exists(APPPATH.'controllers'. DIRECTORY_SEPARATOR . $directory. DIRECTORY_SEPARATOR .ucfirst($class).'.php'))
        {
            // This will trigger 404 later
            return;
        }

        $this->set_directory($directory);
        $this->set_class($class);
        $this->set_method($method);

        // Assign routed segments, index starting from 1
        $this->uri->rsegments = array(
            1 => $class,
            2 => $method
        );

        log_message('debug', 'No URI present. Default controller set.');
    }

And it works, but if this is safe?

  • You should place my link in your answer –  Jan 20 '17 at 06:21
  • https://github.com/wolfgang1983/CI3-default_controller_route_with_sub_folder/tree/master/application/core –  Jan 20 '17 at 06:21
  • but i found that from here http://stackoverflow.com/questions/30397000/default-controller-inside-subfolder-codeigniter-3-not-working @wolfgang1983 – Farhan Afandi Jan 20 '17 at 08:15
  • The original question was asked on here I am guessing the copied the code https://forum.codeigniter.com/thread-63443.html –  Jan 20 '17 at 08:29