如何将数组传递给Drupal的菜单回调 [英] How to Pass Arrays to Drupal Menu Callbacks

查看:117
本文介绍了如何将数组传递给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 code:

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 正在正确传输,但回调倒不工作。我的问题:如何将我数组传递给菜单回调?我应该还是使用占位符的 $项目键?

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 ?

推荐答案

您传递给 $的第二个参数。后()未连接到您传递的网址第一个参数;它是传递到PHP中 $数据_ POST

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,
);

您网页的回调应该然后找到 $从jQuery的传递的数据_ POST

Your page callback should then find the data passed from jQuery in $_POST.

这篇关于如何将数组传递给Drupal的菜单回调的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆