2012-12-16 17 views
1

我有一個網絡應用,我的所有的文件夾是的public_html這樣下:如何訪問我的上齒根文件夾中的public_html從我的MVC的PHP應用程序

的public_html
    -pages
    - 模板
    - 包括
    -styles
    -scripts
    -images
   的index.php

所以我的網站工作的完美,並在直播服務器(使用PHP 5.2.17版本),但我想對等維護一個面向對象的方法改變了一切並試圖學習和Zend框架結構模型的啓發,所以我改變了我的文件夾結構和它完美的本地appache,新的結構是這樣的:

應用
    -models
個    -controllers
    -views
    -config
    -layouts
        -templates

    -functions
的public_html
    -styles
    -scripts
    -images
   的index.php

所以,我將其傳輸到服務器的生活,現在我的主要應用是從根(的public_html),當然還有我可以不從public_html訪問上級根文件夾(應用程序,庫),當然index.php由url
我可以包括他們,但我需要訪問url在一個錨標記的情況下,例如acceptess我的login.php裏面的視圖文件夾裏面的應用程序文件夾。 也需要通過url從我的腳本文件夾訪問控制器文件夾(對於ajax調用等)。
我已經閱讀過我需要使用.htaccess文件,但我不知道我應該使用什麼規則,我應該在哪裏放置它,以及如何在有需要時幫助我。 請告訴我該怎麼辦?
關於

+0

在MVC模型中,您通常不會嘗試直接使用URL訪問「views」文件夾內的文件。 –

回答

2

你錯了。仔細看看任何MVC框架(例如,Zend提到的)。一切都通過公用文件夾內的index.php。您不需要通過URL訪問公共文件夾下的任何內容(實際上,出於安全原因應該禁止它)。您可以通過內部程序結構和重寫規則訪問控制器的操作。通常,每個請求都強行路由到index.php,然後你的應用程序決定它將進一步發展。

+0

感謝您的快速answer.but我hav分離我的索引部分作爲navbar.php footer.php等等,並在我的導航欄作爲我的菜單是我需要引用我的索引頁是index_view.php裏面的視圖文件夾和它給它的控制器裏面也包括它也可以告訴我更多,因爲我沒有完全理解你的意思。我對mvc.thanks很新穎 – azad6026

+1

你可以將你的文件包含在PHP腳本中並不重要在文件系統中的哪個位置他們實際上位於。爲什麼不在腳本中包含你的navbar.php和footer.php?你不需要URL訪問它們。 – ualinker

0

順便看看笨,一個MVC框架,處理文件路由在它自己的index.php file

 
$system_path = 'system'; 
$application_folder = 'application'; 
$view_folder = ''; 

/* 
* --------------------------------------------------------------- 
* Resolve the system path for increased reliability 
* --------------------------------------------------------------- 
*/ 

    // Set the current directory correctly for CLI requests 
    if (defined('STDIN')) 
    { 
     chdir(dirname(__FILE__)); 
    } 

    if (($_temp = realpath($system_path)) !== FALSE) 
    { 
     $system_path = $_temp.'/'; 
    } 
    else 
    { 
     // Ensure there's a trailing slash 
     $system_path = rtrim($system_path, '/').'/'; 
    } 

    // Is the system path correct? 
    if (! is_dir($system_path)) 
    { 
     header('HTTP/1.1 503 Service Unavailable.', TRUE, 503); 
     exit('Your system folder path does not appear to be set correctly. Please open the following file and correct this: '.pathinfo(__FILE__, PATHINFO_BASENAME)); 
    } 

/* 
* ------------------------------------------------------------------- 
* Now that we know the path, set the main path constants 
* ------------------------------------------------------------------- 
*/ 
    // The name of THIS file 
    define('SELF', pathinfo(__FILE__, PATHINFO_BASENAME)); 

    // Path to the system folder 
    define('BASEPATH', str_replace('\\', '/', $system_path)); 

    // Path to the front controller (this file) 
    define('FCPATH', str_replace(SELF, '', __FILE__)); 

    // Name of the "system folder" 
    define('SYSDIR', trim(strrchr(trim(BASEPATH, '/'), '/'), '/')); 

    // The path to the "application" folder 
    if (is_dir($application_folder)) 
    { 
     if (($_temp = realpath($application_folder)) !== FALSE) 
     { 
      $application_folder = $_temp; 
     } 

     define('APPPATH', $application_folder.'/'); 
    } 
    else 
    { 
     if (! is_dir(BASEPATH.$application_folder.'/')) 
     { 
      header('HTTP/1.1 503 Service Unavailable.', TRUE, 503); 
      exit('Your application folder path does not appear to be set correctly. Please open the following file and correct this: '.SELF); 
     } 

     define('APPPATH', BASEPATH.$application_folder.'/'); 
    } 

    // The path to the "views" folder 
    if (! is_dir($view_folder)) 
    { 
     if (! empty($view_folder) && is_dir(APPPATH.$view_folder.'/')) 
     { 
      $view_folder = APPPATH.$view_folder; 
     } 
     elseif (! is_dir(APPPATH.'views/')) 
     { 
      header('HTTP/1.1 503 Service Unavailable.', TRUE, 503); 
      exit('Your view folder path does not appear to be set correctly. Please open the following file and correct this: '.SELF); 
     } 
     else 
     { 
      $view_folder = APPPATH.'views'; 
     } 
    } 

    if (($_temp = realpath($view_folder)) !== FALSE) 
    { 
     $view_folder = realpath($view_folder).'/'; 
    } 
    else 
    { 
     $view_folder = rtrim($view_folder, '/').'/'; 
    } 

    define('VIEWPATH', $view_folder); 

你不應該依賴於.htaccess,你可能會遇到的問題與在mod_rewrite無法使用環境。

此外,不要從超鏈接加載views/目錄中的文件。將所有這些來自index.php頁面的請求路由到您的controllers/,然後,然後使用這些類來加載文件。再次仔細查看CodeIgniter的來源以獲取想法。

相關問題