I am having some difficulties rerouting to a dynamic URL from within my controller.
in routes.ini
GET /admin/profiles/patient/#patientId/insert-report = Admin->createReport
in the controller Admin.php, in method createReport():
$patientId = $f3->get('PARAMS.patientId');
My attempt (in Admin.php):
$f3->reroute('admin/profiles/patient/' . echo (string)$patientId . '/insert-report');
Question: How to reroute to the same URL (where some error messages will be displayed) without
changing completely the routing, that is attaching patientId as a URL query parameter ?
Thanks, K.
The echo statement is not needed to concatenate strings:
$f3->reroute('admin/profiles/patient/' . $patientId . '/insert-report');
Here are 3 other ways to get the same result:
1) build the URL from the current pattern
(useful for rerouting to the same route with a different parameter)
// controller
$url=$f3->build($f3->PATTERN,['patientId'=>$patientId]);
$f3->reroute($url);
2) reroute to the same pattern, same parameters
(useful for rerouting from POST/PUT/DELETE to GET of the same URL)
// controller
$f3->reroute();
3) build the URL from a named route
(useful for rerouting to a different route)
;config file
GET #create_report: /admin/profiles/patient/#patientId/insert-report = Admin->createReport
// controller
$url=$f3->alias('create_report',['patientId'=>$patientId']);
$f3->reroute($url);
or shorthand syntax:
// controller
$f3->reroute(['create_report',['patientId'=>$patientId']]);
Related
Good Afternoon,
I have a external GET request hitting a controller action but i cannot retrieve the params.
the URL looks like:
https://yourway.local/strava/webstatusrep?hub.verify_token=STRAVA&hub.challenge=15f7d1a91c1f40f8a748fd134752feb3&hub.mode=subscribe
i have tried using
$param1 = $request->getQueryParam('hub.challenge');
or
$param = ArrayHelper::getValue(Yii::$app->request->get(), 'hub.challenge');
But also in Xdebug i can see they are not sitting in the “queryparams” section.
Just replace . with _ in param name when calling Yii2 api:
$paramValue = Yii::$app->request->get("hub_challenge");
I'm working on a site on local server. I have made a form to search country,state and city. After getting the results I see the URL formatted as URL
I want to make this URL as URL
So here I want to know about URL manager rules so I can make it as I want.
Simply add this rule in your url-manager
"site/searchme/<country>/<state>/<city>" => "site/searchme"
Now, you need to have an action with this signature:
public function actionSearchme($country, $state, $city)
You can access $country, $state, $city from url inside this action. For example if your url be like http://localhost/yii_1/site/searchme/UnitedStates/Washington/NewYork, $country will equal "UnitedStates" and so on.
I'm new to phalcon and I need assistance because i cannot find a way to get full path url (and add it in an email message) such as :
"http://phalcon.mydomain.com/auth/confirmRegistration"
the most i could get is "/auth/confirmRegistration"
using $this->url->getStatic('auth/confirmRegistration')
there might be a build in function but i could not discover it, or maybe i should put the 'http://phalcon.mydomain.com' part in a global variable ??
thank you in advance
Here's a simple way to get the url of the current page in Phalcon:
echo $this->router->getRewriteUri();
You could do two things. Per documentation you could set the full domain url:
<?php
$url = new Phalcon\Mvc\Url();
//Setting a relative base URI
$url->setBaseUri('/invo/');
//Setting a full domain as base URI
$url->setBaseUri('//my.domain.com/');
//Setting a full domain as base URI
$url->setBaseUri('http://my.domain.com/my-app/');
Or you could simply use HTTP_HOST / SERVER_NAME to get the host name and append the rest of it, e.g:
echo 'http://' . $_SERVER['SERVER_NAME'] . '/auth/confirmRegistration';
I am using Yii 1.1.14.
I want to convert
http://website.com/controller/action?param1=value1¶m2=value2
to
http://website.com/value1/value2
How to do this in urlManager?
First, check this to hide index.php:
http://www.yiiframework.com/doc/guide/1.1/en/topics.url#hiding-x-23x
Then, the route in config.php should be like this:
'<param1:\w+>/<param2:\w+>'=>'mycontroller/myaction',
The method myaction should accept $param1 and $param2 in its constructor to be passed automatically by Yii.
This would make your app unable to look for other controllers, because that rule will accept every route with 2 words separated by /
I am trying to dynamically create a route to my router. I know there is serialize for doing this, but it appears to only accept a finite amount of parameters. For example, I need to be able to build a route that could be /:a or /:a/:b/:c.
My question is, is there a way to get what the original path request was?
I will need to:
get the original path
pause the router so an ajax call can be made to retrieve path info.
request from the server the path and return the module if it exists
(I have that much set up).
If path exists, create the route and move the application into that
state.
You can access the requested location via the router's location property.
You could then split the returned string and access the different parameters.
locationString = App.router.get('location.location.hash')
// something like "/1/2"
params = locationString.split(/\//)
param1 = params[1] // => "1"
param2 = params[2] // => "2"