How can I check my post data in Zend?
I am a beginner and I am creating some forms to be posted into MySQL using Zend, and I am in the process of debugging but I don't really know how to debug anything usi开发者_如何学Pythonng Zend. I want to submit the form and see if my custom forms are concatenating the data properly before it goes into MySQL, so I want to catch the post data to see a few things. How can I do this?
The Default route for zend framework application looks like the following
http://www.name.tld/$controller/$action/$param1/$value1/.../$paramX/$valueX
So all $_GET-Parameters simply get contenated onto the url in the above manner /param/value
Let's say you are within IndexController
and indexAction()
in here you call a form. Now there's possible two things happening:
- You do not define a Form-Action, then you will send the form back to
IndexController:indexAction()
- You define a Form action via
$form->setAction('/index/process')
in that case you would end up atIndexController:processAction()
The way to access the Params is already defined above. Whereas $this->_getParam()
equals $this->getRequest()->getParam()
and $this->_getAllParams()
equals $this->getRequest->getParams()
The right way yo check data of Zend Stuff is using Zend_Debug as @vascowhite has pointed out. If you want to see the final Query-String (in case you're manually building queries), then you can simply put in the insert variable into Zend_Debug::dump()
you can use $this->_getAllParams();
.
For example: var_dump($this->_getAllParams()); die;
will output all the parameters ZF received and halt the execution of the script. To be used in your receiving Action.
Also, $this->_getParam("param name");
will get a specific parameter from the request.
The easiest way to check variables in Zend Framework is to use Zend_Debug::dump($variable);
so you can do this:-
Zend_Debug::dump($_POST);
Zend framework is built on the top of the PHP . so you can use var_dump($_POST) to check the post variables.
ZF has provided its own functions to get all the post variables.. Zend_Debug::dump($this->getRequest()->getPost())
or specifically for one variable.. you can use Zend_Debug::dump($this->getRequest()->getPost($key))
You can check post data by using zend
$request->isPost()
and for retrieving post data
$request->getPost()
For example
if ($request->isPost()) {
$postData = $request->getPost();
Zend_Debug::dump($postData );
}
精彩评论