Symfony1 Symfony寻呼机-组件-查询问题
我使用symfony 1.4.11。我有下一个组件类:Symfony1 Symfony寻呼机-组件-查询问题,symfony1,symfony-1.4,pager,Symfony1,Symfony 1.4,Pager,我使用symfony 1.4.11。我有下一个组件类: class companiesComponents extends sfComponents { public function executeCompanylist(sfWebRequest $request) { // And the URL if (!isset($this->url)) { throw new Exception('Please speci
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';
}
我有allsuces.php
<?php include_component('companies', 'companylist', array(
'query' => $query,
'url' => $url,
'noneFound' => __('You haven\'t created any ads yet.')
)) ?>
这是不可行的。我从数据库中获取所有记录“公司”,但它们不是根据我的查询选择的。。。
当我
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()
我不明白它是如何获得所有记录的,我在哪里犯了错误:(
谢谢!从getAllCompany()函数中的return语句中删除->execute();
文本…doctrinePage执行该语句-您不需要
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;
}
安装XDebug,您将获得完整的堆栈跟踪,而不仅仅是错误消息。顺便说一下,它应该是
addOrderBy
,而不是addOrderBy
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;
}