Symfony 寻呼机 - 组件 - 查询问题

发布于 2024-11-08 01:50:54 字数 2833 浏览 0 评论 0原文

我使用 symfony 1.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';
  }

并且我

 <?php include_component('companies', 'companylist', array(
        'query' => $query,
        'url' => $url,
        'noneFound' => __('You haven\'t created any ads yet.')
        )) ?>

在我的 Companies Table 类中

   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');
}

有 allSucess.php但它不起作用。我从数据库中获取所有记录“公司”,但它们不是根据我的查询选择的... 当我制作

  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() 

我不明白它如何获得所有记录,以及我在哪里犯了错误:(

谢谢!

I use symfony 1.4.11 .I have next component class:

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');
    }

I have action:

public function executeAll(sfWebRequest $request)
  {
    $this->query = Doctrine_Core::getTable('Companies')->getAllCompany();
        $this->url = '@companylist';
  }

And I have allSucess.php

 <?php include_component('companies', 'companylist', array(
        'query' => $query,
        'url' => $url,
        'noneFound' => __('You haven\'t created any ads yet.')
        )) ?>

In my Companies Table class

   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');
}

And it is do not work. I get all my record "companies" from database,but they are not selected according to the my query...
When I make

  public function getAllCompany()
      {
        }

or when I comment

 // $this->pager->setQuery($this->query);

I still get all my records :(

In logs I see :

Template: companies … allSuccess.php 

Parameters:
$query (NULL)
$url (string)

When I make

 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();
}

I have error:

Fatal error: Call to undefined method Doctrine_Collection::offset() 

I do not understand how it get all records, and where I made mistake :(

Thank you!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

等待圉鍢 2024-11-15 01:50:54

从 getAllCompany() 函数的 return 语句中删除 ->execute(); 文本... DoctrinePager 执行该语句 - 您不需要...

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;
}

remove the ->execute(); text from the return statement in the getAllCompany() function ... the DoctrinePager executes the statement - you don't need to ...

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;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文