2

リクエストクラスについて学んでいます。

私はこのURLを持っていますhttp://localahost/blog/search?year=2013&month=07

試しprint_r($_GET)てみると、期待どおりに配列が返されます。

試しprint_r($request->getQuery()); てみると、空のオブジェクトが返されますZend\Stdlib\Parameters Object ( [storage:ArrayObject:private] => Array ( ) )

だからecho $request->getQuery()->year;何も返さない...

私の .htaccess (必要な場合)

RewriteEngine On
# The following rule tells Apache that if the requested filename
# exists, simply serve it.
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
# The following rewrites all other queries to index.php. The 
# condition ensures that if you are using Apache aliases to do
# mass virtual hosting, the base path will be prepended to 
# allow proper resolution of the index.php file; it will work
# in non-aliased environments as well, providing a safe, one-size 
# fits all solution.
RewriteCond %{REQUEST_URI}::$1 ^(/.+)(.+)::\2$
RewriteRule ^(.*) - [E=BASE:%1]
RewriteRule ^(.*)$ %{ENV:BASE}index.php [NC,L]
4

1 に答える 1

5

コメントで言及されているように、あなたがしていることは、あなたがしていることでした

$request= new $request();

知っておく必要があるのは、AbstractActionControllerでクラスを拡張する場合、 $request= new $request()を実行する必要がないということです。AbstractActionControllerが提供する

getRequest()

そこからリクエストとそのデータを取得できます。

于 2013-07-19T22:53:08.163 に答える