Greetings,
I have been working on an interface to edit a tree of modified
Zend_Navigation_Containers for a menus module. On the server side, my
Admin controller has a couple of action functions for AJAX access, and
on the client side, I use jQuery to retrieve the data from one action,
jsTree to handle the UI side, and have code to send the tree back to the
server using a second action. It works great, but for one important
thing... the data transmitted via the POST is not seen by my controller
action. Using firebug, I see the data going across from my workstation,
and have even verified the traffic to the web server using wireshark. I
also know from logging that the action gets executed, but the posted
data is nowhere in the request. I have even tried doing things such as
a Zend_Debug::dump($this...) as well as dumping the superglobals to see
if it is hidden in some unexpected location, and just in case it was a
problem, even set always_populate_raw_post_data in my php.ini. Nowhere
is the data visible to my application that I can see.
I am attaching snippets from my controller and javascript, along with
the packet captured by wireshark.
Additional information...
* ZF server is the zend-server-ce-php-5.3-5.0.4-55 and other
packages, installed from
ZendServer-5.0.3-RepositoryInstaller-linux.tar.gz, and then
updates pulled via yum. Host OS is Centos 5.5.
NOTE: I have a nice little script which allows the Zend
Server to run under SELinux. :) Interested Matthew?
* Another module works fine with a POST action to handle user
login via a form.
* Virtual hosting on this server points to a number of copies of
the project.
Can anyone see what I am doing wrong?? I would really like to solve
this in the next 48 hours or so, as it is holding up things for a
development milestone. And if you have any suggestions for
improvements, I will gladly take them.
Thanks!
- Doug
<?php
class Menus_AdminController extends Zend_Controller_Action
{
public function init()
{
/*
* Register some of our actions as AJAX actions.
*/
$ajaxContext = $this->_helper->getHelper('AjaxContext');
$ajaxContext->addActionContext('list', array('xml','json'))
->addActionContext('getjstree', 'json')
->addActionContext('updatejstree', array('json', 'xml',
'html'))
->addActionContext('modify', 'xml')
->setAutoJsonSerialization(false)
->initContext();
}
public function getjstreeAction()
{
$jstree = array();
$mm = new Menus_Model_MenuMapper();
$menu = $mm->fetchMenu();
$this->view->jstree = $this->_menu_to_jstree($menu);
}
public function updatejstreeAction()
{
/*
* Get the bootstrap, which allows us to bootstrap other things.
*/
$bootstrap = $this->getInvokeArg("bootstrap");
/*
* Make sure the logger is bootstrapped, and get the logger
instance.
*/
$bootstrap->bootstrap('logger');
$logger = $bootstrap->getResource('logger');
/*
* Get the request.
*/
$request = $this->getRequest();
/*
* Make sure this came via a POST, and if not, redirect to
* the index.
*/
if (!$request->isPost()) {
return($this->_helper->redirector('Admin', 'index'));
}
/*
* Turn off rendering.
*/
$this->_helper->viewRenderer->setNoRender();
/*
* Get the params.
*/
$params = $request->getParams();
Zend_Debug::setSapi('cli');
$debug = Zend_Debug::dump($request, PHP_EOL . '$request:' .
PHP_EOL, false);
$debug .= Zend_Debug::dump($params, PHP_EOL . '$params:' .
PHP_EOL, false);
$logger->log('Menus/AdminController/updatejstree' . PHP_EOL .
$debug, Zend_Log::DEBUG);
}
}
$(function()
{
/*
* Tell jstree to manage a tree representing the menus. The
* jstree plugin will request the menu data in json format as a
* subset of the data in the database.
*/
$("#menuedit2").jstree(
{
"json_data" : {
"ajax" : {
"url" : "/Menus/Admin/getjstree/format/json"
}
},
"themes" : {
"dots" : true,
"icons" : false
},
"plugins" : [ "json_data", "dnd", "crrm", "themes" ]
});
$("#testsave").click(function()
{
var $li_opts = [ "id", "class" ]
var $a_opts = ["id"];
var $a = $.jstree._reference("#menuedit2");
var $b = $.jstree._reference("#menuedit2").get_json(null, $li_opts,
$a_opts);
$.post(
"/Menus/Admin/updatejstree/format/json",
$b.toSource(),
function(data)
{
alert($data);
return false;
},
'bogus'
);
return false;
});
return false;
});
No. Time Source Destination Protocol Info
14 0.005109 192.168.11.3 192.168.10.4 HTTP POST
/Menus/Admin/updatejstree/format/json HTTP/1.1
(application/x-www-form-urlencoded)
Frame 14 (1226 bytes on wire, 1226 bytes captured)
Ethernet II, Src: Intel_60:a3:19 (00:0e:0c:60:a3:19), Dst: Supermic_74:ec:b2
(00:30:48:74:ec:b2)
Internet Protocol, Src: 192.168.11.3 (192.168.11.3), Dst: 192.168.10.4
(192.168.10.4)
Transmission Control Protocol, Src Port: 59014 (59014), Dst Port: http (80),
Seq: 5969, Ack: 1, Len: 1172
[Reassembled TCP Segments (7140 bytes): #4(819), #6(769), #8(1460), #10(1460),
#12(1460), #14(1172)]
Hypertext Transfer Protocol
POST /Menus/Admin/updatejstree/format/json HTTP/1.1\r\n
Host: intranet2-dev.home.ka8zrt.com\r\n
User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.15)
Gecko/20101027 Fedora/3.5.15-1.fc12 Firefox/3.5.15\r\n
Accept: */*\r\n
Accept-Language: en-us,en;q=0.5\r\n
Accept-Encoding: gzip,deflate\r\n
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7\r\n
Content-Type: application/x-www-form-urlencoded; charset=UTF-8\r\n
X-Requested-With: XMLHttpRequest\r\n
Referer: http://intranet2-dev.ka8zrt.com/Menus/Admin/editMenu\r\n
Content-Length: 6321\r\n
Cookie: ZDEDebuggerPresent=php,phtml,php3;
PHPSESSID=g9c8naq78833nddqofb4psstu1\r\n
Pragma: no-cache\r\n
Cache-Control: no-cache\r\n
Max-Forwards: 10\r\n
Via: 1.1 intranet2-dev.ka8zrt.com\r\n
X-Forwarded-For: 192.168.10.192\r\n
X-Forwarded-Host: intranet2-dev.ka8zrt.com\r\n
X-Forwarded-Server: intranet2-dev.ka8zrt.com\r\n
\r\n
Line-based text data: application/x-www-form-urlencoded
[truncated] [{data:{attr:{id:"uid1"}, title:"Home"}, attr:{}, state:"open",
metadata:{order:1, uid:1}, children:[{data:{attr:{id:"uid7"}, title:"Main"},
attr:{}, state:"open", metadata:{order:1, uid:7, parent_uid:1}},
{data:{attr:{id:"uid8