To get the request pathinfo use the function $this->_request->getPathInfo() in the controller
How to disable the In Array validator in Zend Form?
When we use multiple select or checkbox option, there is default validator so that the value should not be empty. We can bypass it using the function setRegisterInArrayValidator
Ex: $selCategories = new Zend_Form_Element_MultiCheckbox('categories', array(
'multiOptions' => $categories));
$selCategories->setRegisterInArrayValidator(false);
Ex: $selCategories = new Zend_Form_Element_MultiCheckbox('categories', array(
'multiOptions' => $categories));
$selCategories->setRegisterInArrayValidator(false);
How to save Log in a text file using Zend Framework
We can do that using Zend Log & Zend Log Writer Stream classes.
Ex:
$logText = 'TEST TO LOG THE STRING IN TEXT FILE';
$stream = fopen('/var/www/log/path/filename.txt', 'a');
if( $stream ){
$writer = new Zend_Log_Writer_Stream($stream);
$logger = new Zend_Log($writer);
$logger->log($logText,Zend_Log::INFO);
}
Ex:
$logText = 'TEST TO LOG THE STRING IN TEXT FILE';
$stream = fopen('/var/www/log/path/filename.txt', 'a');
if( $stream ){
$writer = new Zend_Log_Writer_Stream($stream);
$logger = new Zend_Log($writer);
$logger->log($logText,Zend_Log::INFO);
}
How to redirect in Zend Framework without using standard redirect function
If you want to use Zend redirect without using standard redirect function from controller, you can use the below code in any of the plugin or function.
$redirector = Zend_Controller_Action_HelperBroker::getStaticHelper('redirector');
$redirector->gotoUrl('/profile/change-password/')->redirectAndExit();
$redirector = Zend_Controller_Action_HelperBroker::getStaticHelper('redirector');
$redirector->gotoUrl('/profile/change-password/')->redirectAndExit();
How to get HTTP REFERER value in Zend Framework
You can get that directly in Controller using the below code
$requestUri = $this->getRequest()->getServer('HTTP_REFERER');
If you want to get that outside of Controller you can use the Zend Front Contorller class
$requestUri = Zend_Controller_Front::getInstance()->getRequest()->getRequestUri();
$requestUri = $this->getRequest()->getServer('HTTP_REFERER');
If you want to get that outside of Controller you can use the Zend Front Contorller class
$requestUri = Zend_Controller_Front::getInstance()->getRequest()->getRequestUri();
How to get method name in controller while we try Zend JSON Service call
You can use the below code in your controller to get the method name while you try jQuery.Zend.Jsonrpc service call
if($_SERVER['REQUEST_METHOD'] == 'POST') {
$data = json_decode(urldecode($this->getRequest()->getRawBody()));
echo $data->method;
}
if($_SERVER['REQUEST_METHOD'] == 'POST') {
$data = json_decode(urldecode($this->getRequest()->getRawBody()));
echo $data->method;
}
jQuery.Zend.jsonrpc returns error 'not a function' with cross domain request
There is a chance to retun 'not a function' error in console while we try the remote url.
You can fix that with the following changes
1. Use the latest jquery file
2. Remove the 'content-type' attribute from jquery.zend.jsonrpc.js
3. Add the property 'crossDomain: true' in jquery.zend.jsonrpc.js with ajax request
4. Set the header("Access-Control-Allow-Origin: *") in your server script.
I have followed the below url and updated the file with above condition then it works fine.
http://sourcecodebean.com/archives/creating-a-json-rpc-service-using-zend-json-server/422
You can fix that with the following changes
1. Use the latest jquery file
2. Remove the 'content-type' attribute from jquery.zend.jsonrpc.js
3. Add the property 'crossDomain: true' in jquery.zend.jsonrpc.js with ajax request
4. Set the header("Access-Control-Allow-Origin: *") in your server script.
I have followed the below url and updated the file with above condition then it works fine.
http://sourcecodebean.com/archives/creating-a-json-rpc-service-using-zend-json-server/422
Subscribe to:
Posts (Atom)