2017-09-01 23 views
0

我剛開始使用CodeIgniter,我被卡在文檔中的hello世界代碼。每次我在網址欄中的博客控制器的名稱類型,並敲回車,我得到這個錯誤:

本地主機/ PHP /笨/的.htaccessCodeignite hello世界代碼在文檔doent工作

RewriteEngine On 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*)$ index.php/$1 [L] 



路線.PHP

$route['default_controller'] = 'welcome'; 
$route['404_override'] = ''; 
$route['translate_uri_dashes'] = FALSE; 


的config.php

$config['base_url'] = 'http://localhost/php/CodeIgniter/'; 
$config['index_page'] = 'index.php'; 


控制器/ blog.php的

<?php 
    class Blog extends CI_Controller { 

      public function index() 
      { 
        echo 'Hello World!'; 
      } 
    } 

我該如何解決?

回答

0

您必須在[route.php]對應的控制器類/方法上設置一個URL字符串。

$route['default_controller'] = 'blog/index'; 
$route['blog/(:any)'] = 'blog/show/$1' 

您可以將網址 「http://localhost/」 參考 「/」 作爲主場被default_controller上route.php

$config['base_url'] = 'http://localhost'; 

請瀏覽更多的.htaccess和友好的URL。如果你得到404錯誤,也許你的網址不友善。

友好:

http://localhost/blog/lorem-ipsum 

並不友好:

http://localhost/index.php/blog/lorem-ipsum 

文檔:https://www.codeigniter.com/userguide3/general/routing.html

相關問題