私はsymfony1.4.11を使用しています。次のコンポーネントクラスがあります:
class companiesComponents extends sfComponents {
public function executeCompanylist(sfWebRequest $request) {
// And the URL
if (!isset($this->url)) {
throw new Exception('Please specify the URL');
}
// Save the page
if ($request->getParameter('page')) {
$this->setPage($request->getParameter('page'));
}
// Create pager
$this->pager = new sfDoctrinePager('Companies', sfConfig::get('app_ads_per_page', 5));
$this->pager->setQuery($this->query);
$this->pager->setPage($this->getPage());
$this->pager->init();
}
protected function getPager($query) {
$pager = new Doctrine_Pager($query, $this->getPage(), 3);
return $pager;
}
protected function setPage($page) {
$this->getUser()->setAttribute('users.page', $page, 'admin_module');
}
protected function getPage() {
return $this->getUser()->getAttribute('users.page', 1, 'admin_module');
}
私には行動があります:
public function executeAll(sfWebRequest $request)
{
$this->query = Doctrine_Core::getTable('Companies')->getAllCompany();
$this->url = '@companylist';
}
そして私はallSucess.phpを持っています
<?php include_component('companies', 'companylist', array(
'query' => $query,
'url' => $url,
'noneFound' => __('You haven\'t created any ads yet.')
)) ?>
私の会社のテーブルクラスで
public function getAllCompany()
{
$q = $this->createQuery('a')
->andWhere('a.active = ?',1)
->leftJoin('a.Owner o')
->leftJoin('o.Profile p')
->andWhere('p.payed_until > NOW()')
->addORDERBY ('created_at DESC');
}
そして、それは動作しません。データベースからすべてのレコード「会社」を取得しましたが、クエリに従って選択されていません...作成すると
public function getAllCompany()
{
}
または私がコメントするとき
// $this->pager->setQuery($this->query);
私はまだすべての記録を取得しています:(
ログに表示されます:
Template: companies … allSuccess.php
Parameters:
$query (NULL)
$url (string)
私が作るとき
public function getAllCompany()
{
$q = $this->createQuery('a')
->andWhere('a.active = ?',1)
->leftJoin('a.Owner o')
->leftJoin('o.Profile p')
->andWhere('p.payed_until > NOW()')
->addORDERBY ('created_at DESC');
return $q->execute();
}
エラーがあります:
Fatal error: Call to undefined method Doctrine_Collection::offset()
どのようにしてすべてのレコードを取得するのか、どこで間違いを犯したのかわかりません:(
ありがとうございました!