i've read this ad this but nothing is working for me
I'd like to create a menu like this
$items['login'] = array(
'page callback' => 'mymodule_login',
'access arguments' => array('access content'),
'access callback' => true,
'type' => MENU_CALLBACK,
);
in order to send a POST to http://www.example.com/login. The body contains a json with username e password. Everything is ok, except for $_POST under function mymodule_login that does not works. $_POST is empty. What's wrong? Is there another "drupalic" way?
Try this:
$data = file_get_contents("php://input");
Or make sure your form url using trailing slash:
<form action="login/" method="post">
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'm using the Mandrill API to send html email. I have a link in my template that contains a query string with an email address, however the '#' sign is stripped out when receiving the email.
I'm using global_merge_vars thus:
'global_merge_vars' => array(
array(
'name' => 'merge1',
'content' => 'merge1 content'
),
array(
'name' => 'UEMAIL',
'content' => $uEmail
)
),
Example of the link:
http://www.test.com/?email=test#test.com
is received as
http://www.test.com/?email=testtest.com
How can I prevent the '#' from being stripped out?
Thanks!
You have to encode your url because the # sign is special character.
You'll need to URL encode the email address parameter before passing it to Mandrill.
It looks like you're writing in PHP? Try the urlencode function.
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.
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 trying to link a controller action in my home page. this is what i wrote:
<?php $this->Html->link(__('Assign', array('plugin' => 'full_calendar',
'controller' => 'events',
'action' => 'assign',
$events['Event']['id']
)
)
); ?>
but when the home page renders, the button label is /pages/Assign, and the url is pointing to this path: www.mysite.com/pages/Assing
How can I escape from pages controller and link to another controller action?
You are closing the parenthesis wrong :)
<?php $this->Html->link(__('Assign'), array('plugin' => 'full_calendar',
'controller' => 'events',
'action' => 'assign',
$events['Event']['id']
)
); ?>
The __() function should only correspond to the "Assign" string.
Beside that tiny mistake (always happens, so be sure to check for parenthesis mishaps before panicking), the way you're calling the function is ok and it should redirect you correctly.