im trying create url like this: www.domain.com/auth?join=social in yii.
This is my config:
'urlManager' => array(
'urlFormat' => 'path',
'rules' => array(
'<action:(auth)>' => 'site/<action>',
'<controller:\w+>/<action:\w+>' => '<controller>/<action>',
),
'showScriptName'=>false,
),
when i calling this: www.domain.com/auth?join=social page i cant get param: join. But when i calling www.domain.com/index.php/auth?join=social i can get.
im getting param with this code: $social = Yii::app()->request->getParam('join');. Where is my error?
$social = Yii::app()->request->getParam('social');
change it with
$social = Yii::app()->request->getParam('join');
I find my error it wasnt error YII. I must be write rewrite rules in lighttpd configurations. Here explained very well. Thanks!
try
$_REQUEST['join']
in your action.
Related
I typically format my routes in ZF2 like so: /name/to/route
Now I have been doing the same thing with my api routes however I am finding that I am struggling to include data such as encoded urls or arrays.
Here is an example of such a route:
http://example.com/api/register/access/code/c102dea422fa4bb6958d77a29d9873d2/http%3A%2F%2Frouter-local.example.com%2Fapi%2Fdirectory
The following represents forward slashes and thus causes the route not to work: %3A%2F%2
I am thinking I should encode my route as such:
http://example.com/api/register/access/code/?access_code=c102dea422fa4bb6958d77a29d9873d2&route=http%3A%2F%example.com%2Fapi%2Fdirectory
How do you configure the module.config file to deal with this?
Currently it is set as such in apigility:
'api.rpc.register-access-code' => array(
'type' => 'Segment',
'options' => array(
'route' => '/api/register/access/code/:access_code/:route',
'defaults' => array(
'controller' => 'Api\\V1\\Rpc\\RegisterAccessCode\\Controller',
'action' => 'registerAccessCode',
),
),
),
EDIT
I have encoded my routes to include GET parameters by doing the following:
$url = "http://example.com/api/register/access/code/";
$params = [
'access_code' => 'c102dea422fa4bb6958d77a29d9873d2',
'route' => 'http://example.com/api/directory'
];
$final = $url . "?" . http_build_query($params);
Which gives this:
http://example.com/api/register/access/code/?access_code=c102dea422fa4bb6958d77a29d9873d2&route=http%3A%2F%2Fexample.com%2Fapi%2Fdirectory
However this breaks due to a "The requested URL could not be matched by routing." error.
The route is unidentified due to the interpretation of the slashes in the included URL.
Perhaps the issue is to do with how the URL is formatted and included as a parameter?
You don't define query variables in the segment route option; only the path.
You may append ?query=vars to any url, regardless of route configuration. ZF2's url helpers should encode the query vars for you, you just have to create an array of query vars and give it to the helper function when creating a url.
<?php echo $this->url('api.rpc.register-access-code', array(), array('query' => array(
'access_code' => 'c102dea422fa4bb6958d77a29d9873d2',
'route' => 'http://router-local.example.com/api/directory',
))); ?>`
In this case, it would seem the problem is to do with htaccess or apache. The simplest solution has been to encode the url using: base64_encode($url) which can be de-coded at the other end.
I want to generate url with parameters in Laravel like this:
http://example.com/validate_email?user_id=31&confirmation_code=ihlasfsafe
I tried
URL::to('validate_email', array('user_id' => $user_id, 'confirmation_code' => $confirmation_code));
But it gives me:
http://example.com/validate_email/31/ihlasfsafe
So how can I do it correctly?
You need to use:
URL::to('validate_email').'?'.http_build_query(array('user_id' => $user_id, 'confirmation_code' => $confirmation_code));
to achieve this
I pass a query string to SearchController::actionDefault in form of GET parameter q:
/search/?q=...
However I need to define a rule that would automatically initialize this parameter with some value or define another param.
If I'll request mysite.com/showall I need get the same content like in /search/?q=*
This is what I've tried:
'/showall' => '/search/default/index/?r=*',
I solved this!
there is possible to set defaultParams in urlManager, and finaly it looks like in application config file:
...
'components' => array(
...
'urlManager' => array(
...
'rules' => array(
....
'/show_all' => array( '/search/default/index', 'defaultParams' => array('show_all'=>'-') ),
....
),
...
),
...
),
The accepted answer also works when you are getting different requests and you need to map it to the same GET param.
For example I want all of these requests:
user/pics
user/photos
user/pictures
to actually generate: user/index?content=photos.
This might be one of a way to go:
'<controller:user>/(<content:photos>|pics|pictures)' => array('<controller>/index', 'defaultParams'=>array('content'=>'photos')),
I'm new in yii framework and have a problem with url routing.
I have one controller - StaticPage and actions index (default) and send.
Thats my config:
'urlManager' => array(
'showScriptName' => false,
'urlFormat' => 'path',
'rules' => array(
'call' => 'staticPage/index',
'call/send' => 'staticPage/send'
),
),
When i try set pattern like this 'call/<_a>' => 'staticPage/<_a>' i get 404 error, why ?
Always put the more specific rules on top. After a rule matches all following rules will not be checked anymore. That means in your case, if you try the URL /call/send, the first rule will match and route to staticPage/index.
If you want to add 'call/<_a>' => 'staticPage/<_a>' make this the first rule and remove the 'call/send' rule.
This works for me:
'call' => 'staticPage/index',
'call/<action:\w+>' => 'staticPage/<action>',
//or 'call/<action:(send|abc|something)>' => 'staticPage/<action>',
i am trying to go to an location choosen by my script.
I'm using url() and drupal_goto() to archive this, but the fragment-option named at the url()-documentation-page seems not working like i understand it or more likely drupal_goto() is changing the link.
The link-string i want should look like:
/topsection/section#subsection
but instead i'm getting the hash-sign encoded like
/topsection/section%23subsection
Here is my code:
$section = url( '/topsection/' . 'section', array( 'fragment' => 'subsection', 'alias' => TRUE ) );
drupal_goto( $section );
Any help would be nice!
Thank you.
Ha! just found the solution:
I misunderstood the documentation.
It is correctly telling that i should use drupal_goto() with fragment/anchor passed as option like i would give to url().
This is working:
drupal_goto( '/topsection/' . 'section',
array(
'fragment' => 'subsection',
'alias' => TRUE ) );