zf2 zend routing-get-request-Parameter mit $this->params()->fromQuery() funktioniert nicht
habe ich dieses zf2 route config, um die standard-Skelett Anwendung:
(edit: hier meine komplette config:)
'router' => array(
'routes' => array(
'home' => array(
'type' => 'Zend\Mvc\Router\Http\Literal',
'options' => array(
'route' => '/',
'defaults' => array(
'controller' => 'Application\Controller\Index',
'action' => 'index',
),
),
),
'test' => array(
'type' => 'literal',
'options' => array(
'route' => '/test',
'defaults' => array(
'controller' => 'Application\Controller\Index',
'action' => 'test',
),
),
'may_terminate' => true,
'child_routes' => array(
'query' => array(
'type' => 'Query',
'options' => array(
'defaults' => array(
'testparam' => 'bar'
),
),
),
),
),
//The following is a route to simplify getting started creating
//new controllers and actions without needing to create a new
//module. Simply drop new controllers in, and you can access them
//using the path /application/:controller/:action
'application' => array(
'type' => 'Literal',
'options' => array(
'route' => '/application',
'defaults' => array(
'__NAMESPACE__' => 'Application\Controller',
'controller' => 'Index',
'action' => 'index',
),
),
//'may_terminate' => true,
'child_routes' => array(
'default' => array(
'type' => 'Segment',
'options' => array(
'route' => '/[:controller[/:action]]',
'constraints' => array(
'controller' => '[a-zA-Z][a-zA-Z0-9_-]*',
'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
),
'defaults' => array(
),
),
),
),
),
),
),
in der Steuerung möchte ich zu tun bekommen, der request-Parameter innerhalb der testAction:
(edit: hier meine komplette controller):
namespace Application\Controller;
use Zend\Mvc\Controller\AbstractActionController;
use Zend\View\Model\ViewModel;
class IndexController extends AbstractActionController
{
public function indexAction()
{
var_dump(
$this->params()->fromQuery(),
$this->getRequest()->getQuery(),
$this->getEvent()->getRouteMatch()->getParams()
);
return new ViewModel();
}
public function testAction(){
var_dump(
$this->params()->fromQuery(),
$this->getRequest()->getQuery(),
$this->getEvent()->getRouteMatch()->getParams()
);
return new ViewModel();
}
}
URL: /test?testparam=123123
ERGEBNIS: PARAM IST NICHT OK! HIER WÜRDE ICH ERWARTEN, DASS PARAM WERDEN "123123"
wenn ich entfernen may_terminate dann bekomme ich
PARAM = "bar" (see default value for "testparam")
array(0) { } object(Zend\Stdlib\Parameters)#195 (1) { ["storage":"ArrayObject":private]=> array(0) { } } array(3) { ["controller"]=> string(28) "Application\Controller\Index" ["action"]=> string(4) "test" ["testparam"]=> string(3) "bar" }
URL: /?testparam=123123
ERGEBNIS: PARAM IST OK!
array(1) { ["testparam"]=> string(6) "123123" } object(Zend\Stdlib\Parameters)#88 (1) { ["storage":"ArrayObject":private]=> array(1) { ["testparam"]=> string(6) "123123" } } array(2) { ["controller"]=> string(28) "Application\Controller\Index" ["action"]=> string(5) "index" }
keines dieser Werke, die ich nur erhalten NULL-Werte mit der URL: /test?testparam=testvalue
wenn ich diese Anfrage funktioniert es: /?xxx=xycvxcv
(aber ich brauche, um die params aus der testAction()
)
ich eine frische Installation der skeleton application --> Gleiches Ergebnis (nur innerhalb der indexAction
("Heim-Strecke") war es möglich, den request-Parameter ...
- Für mich funktioniert...
- das sieht gut aus..
Du musst angemeldet sein, um einen Kommentar abzugeben.
Die Erste Und Zweite Methode funktioniert für Sie, wenn Sie mit fließenden routing :
URL :
http://localhost/project/public/?ad=23
var_dump :
*EDIT * : Vielleicht sollten Sie entfernen 'may_terminate" - Klausel aus dem array