1

初めての CodeIgniter Web サイトを構築していて、解決が難しいと思われる問題を克服しています..

記事をクリックして読むと、404 ページが表示され続けます。( 見つかりません )

私が得るリンクは次のとおりです

index.php/記事/記事名

私のコントローラーでは、ビュー部分に次のものがあります

    public function view($slug) {
    $data['article_item'] = $this->articles_model->get_article($slug);

    if (empty($data['article_item']))
    {
        show_404();
    }

    $data['title'] = $data['article_item']['title'];

    $this->load->view('templates/header', $data);
    $this->load->view('articles/view', $data);
    $this->load->view('templates/side', $data);
    $this->load->view('templates/footer');
}

ご覧のとおり、article ディレクトリに view.php を含める必要があります。

私のルーターには次のものがあります

    $route['articles/(:any)'] = 'articles/view/$1';
$route['articles/create'] = 'articles/create';
$route['(:any)'] = 'pages/view/$1';
$route['gallery'] = 'gallery';
$route['articles'] = 'articles';
$route['default_controller'] = 'home';
$route['404_override'] = '';

ここに関連するすべてのものを投稿したことを確認するために、私が作成したリンクがあります

<a href="articles/<?php echo $article_item['slug'] ?>" class="button">Read more</a>

そしてモデル

    <?php
class Articles_model extends CI_Model {

    public function __construct() {
        $this->load->database();
    }

    public function get_article($slug = FALSE) {
        if ($slug === FALSE) {
            $query = $this->db->get('articles');
            return $query->result_array();
        }

        $query = $this->db->get_where('articles', array('slug' => $slug));
        return $query->row_array();
    }
}

誰かが私がここで間違っていることを教えてくれることを願っています..

4

1 に答える 1

1

リンクに関数名がありません。

URL は次のようになります: index.php/articles/view/articlename

index.php の後の URL の最初の部分はクラスの名前で、2 番目の部分は関数の名前と入力値です。

于 2013-07-30T08:16:39.773 に答える