2014-05-23 4 views
1

의 컨트롤러에 액세스 할 수 없습니다. 이전 question에 나와 있듯이 myproject-local.com/admin/index 과 같은 URL을 사용하여이 문제를 해결할 수있었습니다. 이제 다른 컨트롤러를 추가했으며 관리 디렉토리에 카테고리를 추가했습니다. 내가 myproject-local.com/admin/category로 이동, 그것은 나에게 404하위 폴더

Routes.php

을 제공
$route['default_controller'] = "welcome"; 
$route['admin/(:any)'] = "admin/admin/$1"; 
$route['404_override'] = ''; 

htaccess로

<IfModule mod_rewrite.c> 
    RewriteEngine On 
    RewriteBase/
    RewriteCond %{REQUEST_FILENAME} !-f 
    RewriteCond %{REQUEST_FILENAME} !-d 
    RewriteRule ^(.*)$ index.php?/$1 [L] 
</IfModule> 

<IfModule !mod_rewrite.c> 

    ErrorDocument 404 /index.php 
</IfModule> 

나는이 방법을 시도해보십시오 config.php를

답변

1

$config['index'] = '';을 설정 한

그 경로를 사용하는 것이 올바른 N '내가 너무 괴롭히지을 추가하는 것으로 이동하는 쉬운 방법을 것 같다 비록
$route['default_controller'] = "welcome"; 
$route['admin/category/(:any)'] = "admin/category/$1"; 
$route['admin/(:any)'] = "admin/admin/$1"; 
$route['404_override'] = ''; 
+0

또한 응용 프로그램의 설정 파일에서의 index.php를 제거하지만, 작품 'myproject-locao.com/admin/index'라고 입력하면 admin 컨트롤러의 색인 작업을로드해야하는 곳인 404가 표시됩니다. – baig772

+0

그냥 이전 질문을 보았습니다. [route] ['admin/(: 모든) '] = "admin/admin/$ 1"; [/ code] –

+0

네, 그렇게 장본한 생각을 위해, 이렇게 내 모든 컨트롤러에 대한 경로를 설정해야합니까 ?? – baig772

2

각 새 컨트롤러에 대한 경로.

locate() 방법을 코어 Router 클래스로 확장하여 다중 레벨 컨트롤러 하위 폴더의 기능을 CodeIgniter로 가져올 수 있습니다. 다음은 확장 된 HMVC 라우터 클래스입니다. HMVC를 사용하지 않는다면 약간의 수정만으로 자신 만의 포크를 작성해야 할 수도 있습니다. 코드는 잘 주석 처리되어 있으며, 읽어 보시고 질문이 있으시면 알려 주시기 바랍니다.

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

// Load HMVC Router 
require APPPATH . 'third_party/MX/Router.php'; 

// ------------------------------------------------------------------------ 

/** 
* Better HMVC Router for CodeIgniter. 
* 
* @package  CodeIgniter 
* @author  Sepehr Lajevardi <[email protected]> 
* @copyright Copyright (c) 2011 Sepehr Lajevardi. 
* @license  http://codeigniter.com/user_guide/license.html 
* @link  https://github.com/sepehr/ci-mx-router 
* @version  Version 1.0 
* @filesource 
*/ 

// ------------------------------------------------------------------------ 

/** 
* HMVC Router extension to support multilevel controller subfolders. 
* 
* @package  CodeIgniter 
* @subpackage Libraries 
* @category Libraries 
* @author  Sepehr Lajevardi <[email protected]> 
* @link  https://github.com/sepehr/ci-mx-router 
*/ 
class MY_Router extends MX_Router { 

    /** 
    * Routes URI segments to the proper module/app controller. 
    * 
    * It's a override of MX_Router's locate() method 
    * to support multilevel controller subfolders. 
    * 
    * @param array $segments URI segments 
    * @return array 
    */ 
    public function locate($segments) 
    { 
     $this->module = $this->directory = ''; 
     $ext = $this->config->item('controller_suffix') . EXT; 

     // Use module route if available 
     if (isset($segments[0]) AND $routes = Modules::parse_routes($segments[0], implode('/', $segments))) 
     { 
      $segments = $routes; 
     } 

     // Get the segments array elements 
     list($module, $directory, $controller) = array_pad($segments, 3, NULL); 

     // ------------------------------------------------------------------------ 
     // 1. Check modules (recursive) 
     // ------------------------------------------------------------------------ 
     foreach (Modules::$locations as $location => $offset) 
     { 
      // Module controllers/ exists? 
      if (is_dir($source = $location . $module . '/controllers/')) 
      { 
       $this->module = $module; 
       $this->directory = $offset . $module . '/controllers/'; 

       // Temporary helper variables 
       $base_directory = $this->directory; 
       $segments_copy = array_slice($segments, 1); 

       do { 
        // Update directory, if not in the first round 
        if (isset($segments_copy[0]) AND $directory !== $segments_copy[0]) 
        { 
         $this->directory = $base_directory . $directory . '/'; 
         $directory  .= '/' . $segments_copy[0]; 
        } 

        // Check if controller file exists 
        if ($directory AND is_file($source . $directory . $ext)) 
        { 
         return $segments_copy; 
        } 

        // Move forward through the segments 
        $segments_copy = array_slice($segments_copy, 1); 
       } 
       while (! empty($segments_copy) AND $directory AND is_dir($source . $directory . '/')); 

       // Check for default module-named controller 
       if (is_file($source . $module . $ext)) 
       { 
        $this->directory = $base_directory; 
        return $segments; 
       } 
      } 
     } // foreach 

     // ------------------------------------------------------------------------ 
     // 2. Check app controllers in APPPATH/controllers/ 
     // ------------------------------------------------------------------------ 
     if (is_file(APPPATH . 'controllers/' . $module . $ext)) 
     { 
      return $segments; 
     } 

     // Application sub-directory controller exists? 
     if ($directory AND is_file(APPPATH . 'controllers/' . $module . '/' . $directory . $ext)) 
     { 
      $this->directory = $module . '/'; 
      return array_slice($segments, 1); 
     } 

     // ------------------------------------------------------------------------ 
     // 4. Check multilevel sub-directories in APPPATH/controllers/ 
     // ------------------------------------------------------------------------ 
     if ($directory) 
     { 
      $dir = ''; 

      do { 
       // Go forward in segments to check for directories 
       empty($dir) OR $dir .= '/'; 
       $dir .= $segments[0]; 

       // Update segments array 
       $segments = array_slice($segments, 1); 
      } 
      while (count($segments) > 0 AND is_dir(APPPATH . 'controllers/' . $dir . '/' . $segments[0])); 

      // Set the directory and remove it from the segments array 
      $this->directory = str_replace('.', '', $dir) . '/'; 

      // If no controller found, use 'default_controller' as defined in 'config/routes.php' 
      if (count($segments) > 0 
       AND ! file_exists(APPPATH . 'controllers/' . $this->fetch_directory() . $segments[0] . EXT)) 
      { 
       array_unshift($segments, $this->default_controller); 
      } 
      else if (empty($segments) AND is_dir(APPPATH . 'controllers/' . $this->directory)) 
      { 
       $segments = array($this->default_controller); 
      } 

      if (count($segments) > 0) 
      { 
       // Does the requested controller exist in the sub-folder? 
       if (! file_exists(APPPATH . 'controllers/' . $this->fetch_directory() . $segments[0] . EXT)) 
       { 
        $this->directory = ''; 
       } 
      } 

      if ($this->directory . $segments[0] != $module . '/' . $this->default_controller 
       AND count($segments) > 0 
       AND file_exists(APPPATH . 'controllers/' . $this->fetch_directory() . $segments[0] . EXT)) 
      { 
       return $segments; 
      } 
     } 

     // ------------------------------------------------------------------------ 
     // 5. Check application sub-directory default controller 
     // ------------------------------------------------------------------------ 
     if (is_file(APPPATH . 'controllers/' . $module . '/' . $this->default_controller . $ext)) 
     { 
      $this->directory = $module . '/'; 
      return array($this->default_controller); 
     } 
    } 

    // ------------------------------------------------------------------------ 

} 
// End of MY_Router class 

/* End of file MY_Router.php */ 
/* Location: ./application/core/MY_Router.php */ 

희망이 있습니다.

+0

이 문제에 대해 자세히 안내해 줄 수 있습니까? 우리는이 전화와 그 사용법을 기재해야합니다. – baig772

0

경로와 함께 hmvc를 사용하면 HMVC에서 모두 제대로 작동합니다. 최신 버전을 다운로드하는 경우 hmvc 경로와 함께 사용하기 때문에 아래와 같이 경로에 함수를 포함해야합니다. 경로에서 hmvc에 대한 다른 스크립트를 추가 할 필요가 없습니다.

$route['default_controller'] = "folder/file/index"; //Works 
$route['404_override'] = ''; 
$route['some_controller_name_a'] = "folder/file/index"; //Works 
$route['some_controller_name_b'] = "folder/file/yourfunction"; //Works 

//My Way 


$route['default_controller'] = "install/common/step_1/index"; 
$route['404_override'] = ''; 

// If default controller does not work with sub folder add it like so then should work. 

$route['step_1'] = "install/common/step_1/index"; 
$route['step_2'] = "install/common/step_2/index"; 
$route['step_3'] = "install/common/step_3/index"; 
$route['step_4'] = "install/common/step_4/index"; 

리디렉션을 사용하면 리디렉션 ('some_controller_name_a')과 유사하게 만들 수 있습니다. 때

사용

Options +FollowSymLinks 
Options -Indexes 
DirectoryIndex index.php 
RewriteEngine on 
RewriteCond $1 !^(index\.php|images|robots\.txt) 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*)$ index.php/$1 [L,QSA] 

이 또한 지금은이 문제에 대한 일보기 파일로드 컨트롤러

<?php echo Modules::run('install/common/header/index');?>