You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Trying to learn to use Sense, I have some doubts that I don't know if are caused by me not know how to do something, or lacking some info on the documentation (recently sent a pull request extending it), or maybe a bug.
So I'm creating a test controller, but instead of using:
class TestController extends AbstractController {
/**
* @Route("/demo/{name}", method="GET", name="test_route")
*/
public function demoAction(Request $request, WP_Query $query) {
As I’m working on a namespace like in the examples, I have to use fully qualified classes for parameter types
<?php
namespace Simettric\Plugin\Controller;
use Simettric\Sense\Annotations\Route; //Needed for the @Route comment anotation
use Simettric\Sense\Controller\AbstractController;
class TestController extends AbstractController {
/**
* @Route("/demo/{name}", method="GET", name="test_route")
*/
public function demoAction(\Symfony\Component\HttpFoundation\Request $request, \WP_Query $query) {
Then, trying to get the $name as a parameter of the method, it doesn't work... it always gives me an error saying that only 2 parameters are expected, and first is expected to be of Request class:
class TestController extends AbstractController {
/**
* @Route("/demo/{name}", method="GET", name="test_route")
*/
public function demoAction($name, \Symfony\Component\HttpFoundation\Request $request, \WP_Query $query) {
//doesn't work as intended
So instead of that, this is what works for me:
/**
* @Route("/demo/{name}", method="GET", name="test_route")
*/
public function demoAction(\Symfony\Component\HttpFoundation\Request $request, \WP_Query $query) {
$name = $request->get('name');
Then, trying to use the requirements clause in the Route, I've already figured out that instead of how it's told in documentation, you have to use like in the following example... but then, request->get('name') doesn't work any more.
class TestController extends AbstractController {
/**
* @Route("/demo/{name}", requirements={"name":"\w+"}, method="GET", name="test_route")
*/
public function demoAction(\Symfony\Component\HttpFoundation\Request $request, \WP_Query $query) {
$name = $request->get('name');
//Now $name is empty
If you tell me a working example of use of requirements and passing an URL parameter, I’ll update the documentation.
The text was updated successfully, but these errors were encountered:
Hi Asier,
Trying to learn to use Sense, I have some doubts that I don't know if are caused by me not know how to do something, or lacking some info on the documentation (recently sent a pull request extending it), or maybe a bug.
So I'm creating a test controller, but instead of using:
As I’m working on a namespace like in the examples, I have to use fully qualified classes for parameter types
Then, trying to get the $name as a parameter of the method, it doesn't work... it always gives me an error saying that only 2 parameters are expected, and first is expected to be of Request class:
So instead of that, this is what works for me:
Then, trying to use the requirements clause in the Route, I've already figured out that instead of how it's told in documentation, you have to use like in the following example... but then, request->get('name') doesn't work any more.
If you tell me a working example of use of requirements and passing an URL parameter, I’ll update the documentation.
The text was updated successfully, but these errors were encountered: