2016-09-03 6 views
0

でポストビューを生成することはできません。私はこのビデオの手順を以下のよCodeIgniterの

https://www.youtube.com/watch?v=ywxIElNbcj4&index=12&list=PLMTiAh6qhda1-MVtXe1vs_99CghP5pd01

indidivualポストに私をクリックすると、ビューがロードされ、私は次のエラーを取得されていません:

An uncaught Exception was encountered

Type: Error

Message: Call to undefined method Post::getPostById()

Filename: C:\xampp\htdocs\aplicacion\application\controllers\article.php

Line Number: 11

Backtrace:

File: C:\xampp\htdocs\aplicacion\index.php Line: 315 Function: require_once"

なぜgetPostById()を認識できないのですか?ライブラリがありませんか?あなたのarticle.phpあなたはPostモデルを含めるか定義していないので、ポスト:: getPostById($ ID)を見つけることができませんでした

https://github.com/ashcrimson/aplicacion

+0

一般化されたコントローラー、ライブラリー、モデル、クラスでは、[convention](https://codeigniter.com/userguide3/general/styleguide.html#file- naming)に従いません。同様の問題を避けるために全ページを読んでください。 – Tpojka

+0

getPostById()関数が何のエラーでないかを教えてくれます – user4419336

+0

あなたの質問はあまり役に立ちません。あなたはarticle.phpとビューにあるコードを投稿してください。 – Franco

答えて

0

これは、ファイルと私のリポジトリですあなたのオートローダーでそれを見つけることができるようにarticle.php。 あなたのコントローラーで、youre getPostById()が存在する投稿モデルを読み込みます。 Code Igniter User Guide

を引用

class Article extends CI_Controller 
{ 
    function __construct() 
    { 
     parent::__construct(); 
     /* Load model in the constructor. 
     * Include the folder name if you have, for example applications/model/admin/post_model.php , 
     * call it as admin/Post_model (where Post_model is your model class name) 
    */ 

    $this->load->model('Post_model','',TRUE); 

    } 
    public function post ($id ='') 
    { 
     /* 
     your code here 
     */  
     //Retrieve data 
      $post = $this->Post_model->getPostById($id)->row(); 
    } 
} 

それは初心者のためのステップのチュートリアルにより、非常に明確なステップがあります。

+0

これは実際にそれを修正しました。ありがとう! –

+0

これを有用とマークすることができれば幸いです。^_ ^ハッピーコーディング! – user1149244

関連する問題