• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
wrong controller in my first CI 3

#1
i just download CI and i take 2 folder application and system to my webfolder,
i move index.php to be inside application and i have modified the .htaccess

my webfolder is C:\onedrive\dropbox\template\
and my access url is http://localhost/template/application/index.php

but every time i open http://localhost/template/application/ always said :
404 Page Not Found, The page you requested was not found.

when i debugging to CodeIgniter.php
PHP Code:
var_dumpt($RTR->class); 
got
Code:
'template'

that why my url always wrong, why this is happened?

i just modify 'Router.php' in method '_set_request' in the first line to exclude my url for segmentation :
PHP Code:
        // akhyar : exclude url before index.php first
        
$excSegment explode('/',config_item('base_url'));
        
$segments array_diff($segments,array('index.php'));
        foreach (
$excSegment as $idxSegment => $valSegment) {
            
$segments array_values(array_diff($segments,array(urlencode($valSegment))));
        } 

become :
PHP Code:
    protected function _set_request($segments = array())
    {
        
// akhyar : exclude url before index.php first
        
$excSegment explode('/',config_item('base_url'));
        
$segments array_diff($segments,array('index.php'));
        foreach (
$excSegment as $idxSegment => $valSegment) {
            
$segments array_values(array_diff($segments,array(urlencode($valSegment))));
        }

        
$segments $this->_validate_request($segments);

        
// If we don't have any segments left - try the default controller;
        // WARNING: Directories get shifted out of the segments array!
        
if (empty($segments))
        {
            
$this->_set_default_controller();
            return;
        }

        if (
$this->translate_uri_dashes === TRUE)
        {
            
$segments[0] = str_replace('-''_'$segments[0]);
            if (isset(
$segments[1]))
            {
                
$segments[1] = str_replace('-''_'$segments[1]);
            }
        }

        
$this->set_class($segments[0]);
        if (isset(
$segments[1]))
        {
            
$this->set_method($segments[1]);
        }
        else
        {
            
$segments[1] = 'index';
        }

        
array_unshift($segmentsNULL);
        unset(
$segments[0]);
        
$this->uri->rsegments $segments;
    } 
Reply

#2
First, you shouldn't be modifying anything in the system directory. Even if you needed to fundamentally alter the way CodeIgniter works for some reason, you could still do so 99.99% of the time without modifying a single file in the system directory.

Second, your issue is a configuration issue, either in your /application/config/config.php file, your .htaccess file, or whatever file you're using to configure your web server (such as a .conf file for Apache).

Third, why did you put your index.php file inside your /application directory? Your /application and /system directories should not be accessible from a web browser, and every request has to be routed through index.php, so it should not be in a directory that should not be accessible from a web browser. I usually put my index.php, all of my CSS/JavaScript/image files, and any documents which need to be available for download in a /public directory, then make that my site's root directory in my Apache .conf file (with /application, /system, etc. outside of that).
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.