gpt4 book ai didi

php - Symfony,在路由方法中获取GET参数

转载 作者:可可西里 更新时间:2023-10-31 23:34:37 24 4
gpt4 key购买 nike

有问题。

有我的路由方法:

book_list:
url: /api/books.:sf_format
class: sfDoctrineRoute
options: { model: Book, type: list, method: getActiveWithAuthor }
param: { module: book, action: list, sf_format: json }
requirements:
sf_format: (?:json|html)

实际代码很简单:

public function executeList(sfWebRequest $request) {
$this->books = $this->getRoute()->getObjects();
}

和获取书籍的自定义方法

public function getActiveWithAuthor(array $parameters) {
// crit is easy to find in logs.
sfContext::getInstance()->getLogger()->crit(var_export($parameters, true));
return BookQuery::create()
->addSelf()
->addAuthor()
->execute();
}

问题是,我想通过可选参数“date_from”来过滤书籍,该参数可以在 url 中,例如/api/books?date_from=2011-02-18

但在日志中我只能看到“sf_format => html”(或 json)我应该使用什么来获取可选参数“date_from”?

最佳答案

public function executeList(sfWebRequest $request) 
{
$this->books = Doctrine::getTable('Book')-> getActiveWithAuthor($request->getParameter('date'));
}

//BookTable.class.php
public function getActiveWithAuthor($date)
{
$q = $this->createQuery('b')
->leftJoin('b.Author')
->where('b.date > ?', $date);

return $q->execute();
}

关于php - Symfony,在路由方法中获取GET参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5068016/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com