私はコードイグナイタープロジェクトにページネーションを追加しようとしています。私は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;
}
}
のですか?前もって感謝します!
どのような種類のエラーが発生していますか? – jondavidjohn
これは私が得るエラーです:致命的なエラー:定義されていないメソッドDoctrine_Collection :: getGifs()をC:\ dev \ yougotgifd \ application \ controllers \ view.php(20行目)で呼び出してください。 – Rapture