2011-02-01 6 views
0

私はコードイグナイタープロジェクトにページネーションを追加しようとしています。私はDoctrineを私のモデルに使用しています。コントローラのメソッドにアクセスするために$ this-> load-> model( 'gif')を使うことはできません。私はDoctrineモデルの動作が異なっていると思いますが、確かにパブリックメソッドを呼び出す方法はありますか?ここでDoctrineモデル(コードイグナイター)のパブリックメソッドへのアクセス

は私のコントローラである:ここでは

<?php 

class View extends Controller 
{ 
    function index() 
    { 
    // load pagination class 
    $gifs = Doctrine::getTable('Gif')->findAll(); 
    $this->load->library('pagination'); 
    $config['base_url'] = base_url().'view/'; 
    $config['total_rows'] = count($gifs); 
    $config['per_page'] = '5'; 
    $config['full_tag_open'] = '<p>'; 
    $config['full_tag_close'] = '</p>'; 

    $this->pagination->initialize($config); 

    //load the model and get results 
    //$this->load->model('gif'); 
    $data['results'] = $gifs->getGifs($config['per_page'],$this->uri->segment(2)); 



    // load the view 

    $this->load->view('front_images', $data); 
    } 
} 

は私のモデルは、私がそのコントローラからnumGifsとgetGifsメソッドを呼び出すことができますどのように

<?php 
class Gif extends Doctrine_Record { 

    public function setTableDefinition() 
    { 
     $this->hasColumn('photo_path', 'string', 255, array('unique' => true, 'notnull' => true)); 
     $this->hasColumn('title', 'string', 255, array('notnull' => true)); 
     $this->hasColumn('user_id', 'integer', 4); 
     $this->hasColumn('token', 'string', 255); 
    } 

    public function setUp() 
    {  
     $this->actAs('Timestampable');  
     $this->hasOne('User', array(
      'local' => 'user_id', 
      'foreign' => 'id' 
     ));  
    } 

    public function preInsert($event) 
    { 
     $this->token = (sha1(rand(11111, 99999))); 
    } 

    public function numGifs() { 

     $result = Doctrine_Query::create() 
      ->select('COUNT(*) as num_gifs') 
      ->from('Gif')   
      ->fetchOne(); 
     return $result['num_gifs']; 

    } 

    public function getGifs($offset, $limit) 
    { 

     $gifs = Doctrine_Query::create()    
      ->from('Gif g')   
      ->orderBy('g.created_at DESC') 
      ->limit($limit) 
      ->offset($offset) 
      ->execute();   
     return $gifs; 
    } 




} 

のですか?前もって感謝します!

+0

どのような種類のエラーが発生していますか? – jondavidjohn

+0

これは私が得るエラーです:致命的なエラー:定義されていないメソッドDoctrine_Collection :: getGifs()をC:\ dev \ yougotgifd \ application \ controllers \ view.php(20行目)で呼び出してください。 – Rapture

答えて

0

私はまた、教義と組み合わせてCIを使用しています。参照のために私はhttp://www.phpandstuff.com/articles/codeigniter-doctrine-from-scratch-day-1-install-and-setupにあるtutoに従っています。

同様の手順に従ったかどうかはわかりませんが、このアプローチモデルを使用すると、ロードする必要はなくインスタンス化する必要があります。例えば、 。

$g = new Gif(); 
$g = $g->getGifs(); 

(この特定のケースでは が - $ gは一列のみ を見込んで - 。私たちはテーブル自体を表すモデルの内側にゲッター機能を定義することができるかどうかわからないtuto午前中にモデル以下のみを含みますdbテーブル定義および任意の関係)

これは役立ちます。

関連する問題