How to Pass Arrays to Drupal Menu Callbacks(如何将数组传递给 Drupal 菜单回调)
问题描述
我在 JavaScript 中有两个数组:var xcoord = [];
和 var ycoord = [];
经过一些处理,每个数组包含 15 个数值.我想将此数据发送到 Drupal 中的菜单回调.
I have two arrays in JavaScript:
var xcoord = [];
and var ycoord = [];
After some processing, each array contains 15 numeric values. I'd like to send this data to a menu callback in Drupal.
我的 AJAX 代码:
My AJAX code:
$.post('http://mysite.com/?q=menu_example/my_page',
{'ycoord[]': ycoord, 'xcoord[]': xcoord }
);
Drupal PHP:
Drupal PHP:
$items['menu_example/my_page/%/%'] = array(
'title' => 'My Page',
'description' => 'i hope this works',
'page callback' => '_graphael',
'page arguments' => array(2, 3), // fill this,
'access callback' => true,
'type' => MENU_CALLBACK,
);
在我的控制台中,我看到 xcoord
和 ycoord
的值正在正确传输,但回调并不完全正常.我的问题:如何将数组传递给菜单回调?我还应该在 $items
键中使用 %
占位符吗?
In my console, I see that the values for xcoord
and ycoord
are being properly transmitted, but the callback isn't quite working. My question: how would I pass arrays to a menu callback? Should I still use a %
placeholder in the $items
key ?
推荐答案
您传递给 $.post()
的第二个参数未附加到您作为第一个参数传递的 URL;它是在 $_POST
中传递给 PHP 的数据.
The second argument you pass to $.post()
is not attached to the URL you pass as first argument; it is data that is passed to PHP in $_POST
.
菜单回调的正确定义应如下所示.
The correct definition for the menu callback should be the following one.
$items['menu_example/my_page'] = array(
'title' => 'My Page',
'description' => 'I hope this works',
'page callback' => '_graphael',
'access callback' => TRUE,
'type' => MENU_CALLBACK,
);
您的页面回调应该会在 $_POST
中找到从 jQuery 传递的数据.
Your page callback should then find the data passed from jQuery in $_POST
.
这篇关于如何将数组传递给 Drupal 菜单回调的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何将数组传递给 Drupal 菜单回调


- 使用 GD 和 libjpeg 支持编译 PHP 2022-01-01
- Laravel 5:Model.php 中的 MassAssignmentException 2021-01-01
- PHP foreach() 与数组中的数组? 2022-01-01
- Oracle 即时客户端 DYLD_LIBRARY_PATH 错误 2022-01-01
- openssl_digest vs hash vs hash_hmac?盐与盐的区别HMAC? 2022-01-01
- 如何从数据库中获取数据以在 laravel 中查看页面? 2022-01-01
- PHP - if 语句中的倒序 2021-01-01
- 覆盖 Magento 社区模块控制器的问题 2022-01-01
- 如何在 Symfony2 中正确使用 webSockets 2021-01-01
- 如何使用 Google API 在团队云端硬盘中创建文件夹? 2022-01-01