2011-06-05 64 views
6

我想在Yii中使用Gii。我的第一個webapp的protected/config/main.php有這部分取消註釋,正如Yii文檔中啓用Gii(123.45.67.123是我嘗試訪問的計算機的公共IP地址)中的說明:Yii 1.1.7 - 無法找到gii頁面

'modules'=>array(
      // uncomment the following to enable the Gii tool 
      'gii'=>array(
        'class'=>'system.gii.GiiModule', 
        'password'=>'123456', 
        // If removed, Gii defaults to localhost only. Edit carefully to taste. 
        'ipFilters'=>array('123.45.67.123','127.0.0.1','::1'), 
      ), 
    ), 

// uncomment the following to enable URLs in path-format 
      'urlManager'=>array(
        'urlFormat'=>'path', 
        'rules'=>array(
          '<controller:\w+>/<id:\d+>'=>'<controller>/view', 
          '<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>', 
          '<controller:\w+>/<action:\w+>'=>'<controller>/<action>', 
        ), 
      ), 

當我去我的Yii網站,例如,www.example.org,基本的Yii頁:

我也通過取消註釋下面在我的保護/配置/ main.php啓用urlManager裝入正常。當我做www.example.org/gii時,我得到了404。當我訪問www.example.org/index.php?r=gii時,我得到了404。爲什麼我的Gii頁面沒有找到?我正在使用CentOS 5.6。

+0

你有沒有啓用.htaccess文件和mod_rewrite? – ZaQ 2011-06-06 03:17:31

+1

是的,.htaccess和mod_rewrite在Apache端啓用。 – user785179 2011-06-06 04:44:47

回答

17

嘗試的路線衝突:

http://www.example.org/index.php/gii

看來你有相同的規則,我做的網址。如果http://www.example.org帶你到你的主要yii webapp頁面,那麼上面的鏈接應該工作。

您打算http://www.example.org/gii這是錯誤的。

+0

是的,那可行!現在這意味着我也可以讓我的urlManager爲乾淨的URL工作!謝謝! – user785179 2011-06-07 03:09:40

+0

我的男人沒問題。 – 2011-06-07 13:13:51

+1

謝謝!我也有乾淨的網址,並想知道爲什麼它不適合我使用index.php?r = gii ..教程中顯示的內容:P – Vicer 2012-11-07 01:23:01

0

您是否嘗試過使用urlManager去激活?只是爲了看看GII本身它使用urlManager喜歡這個工作

+0

完美!現在gii沒有urlManager!那麼我怎麼讓urlManager工作和gii工作? – user785179 2011-06-06 12:30:32

+0

事情是,我知道urlManager正在工作(有點),因爲我的網站頁面看起來像「www.example.org/site/about」。現在,當我禁用urlManager時,它們看起來像index.php?r = site/page&view = about,但是gii有效!就好像urlManager不知道gii頁面。這可能是一個bug? – user785179 2011-06-06 12:37:19

+0

請參閱下面我的答案,用戶。 – 2011-06-06 14:10:45

3

林爲GII

'urlManager'=>array(
    'urlFormat'=>'path', 
    'cacheID' => false, 
    //'caseSensitive' => true, 
    'showScriptName' => false, 
    'urlSuffix' => '/', 
    'rules'=>array(
      'gii'=>'gii', 
      'gii/<controller:\w+>'=>'gii/<controller>', 
      'gii/<controller:\w+>/<action:\w+>'=>'gii/<controller>/<action>', 
... 

,並沒有與其他網站的網頁

+0

不幸的是,這沒有任何影響。當我用你的代碼替換它時,仍然無法讓你的代碼工作。 – user785179 2011-06-06 12:29:53

1

您可以將@ briiC.lv的代碼合併到您的整個urlManager塊嗎?它應該工作,這幾乎是我的一樣:

'urlManager'=>array(
    'urlFormat'=>'path', 
    'rules'=>array(// remove gii for production: 
     'gii'=>'gii', 
     'gii/<controller:\w+>'=>'gii/<controller>', 
     'gii/<controller:\w+>/<action:\w+>'=>'gii/<controller>/<action>', 
     'site/index'=>'/', 
     '<controller:\w+>'=>'site/<controller>', 
     '<filter:(proj|dept)>/<id:\d+>'=>'site/', 
    ), 
    'showScriptName'=>false, 
), 

如果仍然無法正常工作,你可能還需要發佈/鏈接到您的完整main.config文件。

+0

不幸的是,stackoverflow不會讓我複製/粘貼我的整個main.php文件。太多字符 即使使用briiC.Iv的代碼,它仍然無法正常工作。 – user785179 2011-06-07 03:00:02

0

如果已經啓用國防部重寫,並要放置在你的htaccess文件

php_value upload_max_filesize 1M 
DirectoryIndex index.php 

Options +FollowSymlinks 
RewriteEngine on 

# if a directory or a file exists, use it directly 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 

# otherwise forward it to index.php 
RewriteRule . index.php 

以下,並添加以下到「urlManager」陣列在你的配置/ main.php文件:

'showScriptName'=>false, 

會從你的URL中刪除index.php文件,並確保只顯示網址在domain.com/controller/action

0

的形式,我無法訪問www.example.org/gii聯合國直到我在我的虛擬主機配置中添加了以下內容

<Directory /path/to/web/root> 
    Options Indexes FollowSymLinks MultiViews 
    AllowOverride All 
    Order allow,deny 
    Allow from all 
</Directory> 
0

我剛剛遇到了與URL和Gii相同的問題,我發現我寫的IP地址不對。當我從網絡統計更改爲正確的,然後將IP添加到GII的ipFilters。

希望有幫助!