2017-08-31 114 views
1

美好的一天!爲什麼我不斷收到錯誤: - 頁面不存在

是新的代碼點火器,我一直在教程練習手冊上創建博客,

但我認爲網頁口口聲聲說找不到網頁,

這是我的索引:

<h2><?php echo $title; ?></h2> 
 

 
<?php foreach ($news as $news_item): ?> 
 

 

 
    <h3><?php echo $news_item['title']; ?></h3> 
 
    <div class="main"> 
 
      <?php echo $news_item['text']; ?> 
 
    </div> 
 
    <p><a href="<?php echo site_url('news/'.$news_item['slug']); ?>">View article</a></p> <?php endforeach; ?>

這是對每個職位的視圖頁面:view.php

<?php 
 
echo '<h2>'.$news_item['title'].'</h2>'; 
 
echo $news_item['text'];

這是我的路線:

$route['news/create'] = 'news/create'; 
 
`$route['news/create'] = 'news/create'; 
 
$route['news/(:any)'] = 'news/view/$1'; 
 
$route['news'] = 'news'; 
 
$route['(:any)'] = 'pages/view/$1'; 
 
$route['default_controller'] = 'pages/view';`

和我確定在數據庫中的細節。

謝謝你,如果你能幫助

+0

如果你得到404找不到頁面,那麼你的路由一定是錯誤確保它指向一個。實際的控制器和方法,你有一個正確的視圖文件設置等。什麼URL AR你試圖訪問? – delboy1978uk

+0

謝謝,我試圖訪問此鏈接使用 從數據庫中發佈標題slu 012 http://localhost/tut/index.php/news/testing-this-news –

+0

嗯,你沒有一個Apache的VirtualHost設置?我會認爲http:// localhost是項目的根源,這可能是你的問題。您可以創建一個虛擬域名作爲apache將響應的虛擬主機,然後編輯您的OS's主機文件,將127.0.0.1指向您的虛假域。我喜歡打電話給我的dev.whatever.com,但它可以是任何東西!一旦你有一個適當的域名設置,這個問題可能會消失。首先,其他鏈接的工作? – delboy1978uk

回答

0

的index.php在您SITE_URL想念你必須這樣做, 1]在config.php添加的index.php或 2]在錨標記使用的index.php [像:/index.php">View文章]

+0

我的網址是這樣的:http://tut.local/index.php/news/testing-this-news –

0

嘗試添加的index.php到您的鏈接,

<?php echo site_url('index.php/news/'.$news_item['slug']); ?> 
+0

謝謝,雖然我用.htaccess刪除index.php的需要 –

相關問題