zfdatagrid and jqgrid: subgrid is not loading - zend-framework

I am using Zend Framework that's why I decided to use "zfdatagrid deploy jqgrid" instead of using jqgrid straight away.
I want to have jqgrid with subgrid. Grid is shown ok, but when I click expand button then I get notice "Loading" but nothing happens. I have debugged that "subGridUrl" is called correctly, because debugger hit function where I should select data from MySQL for subgrid, and I tried to pass pure json response (instead of selecting from MySQL) but still subgrid is not shown. Maybe I don't understand what response must be? My response:
<...>
$responce = new stdClass();
$responce->rows[0]['id']='0';
$responce->rows[0]['cell']=array('0','test1','123','1');
$responce->rows[1]['id']='1';
$responce->rows[1]['cell']=array('1','test2','321','2');
$j = json_encode($responce);
echo $j;
<...>

Sorry, my bad. But instead of deleting my question, I will explain my mistake incase somebody else will do the same...
I made a mistake declaring "subGridModel". Instead using array:
$jqGrid->setJqgParams(array(
'caption' => 'test report',
<..>
'subGrid' => true,
'subGridUrl' => $this->view->url(array('controller'=>'report','action'=>'indexstoragebalancesubgrid'),'default', true),
'subgridtype' => 'json',
'loadonce' => false,
// next line where problem fixed
'subGridModel' => array(array("name" => array("ID", "Title", "Code", "Quantity"), "width" => array(10,55,200,80)))
<..>
));
I wrote string:
'subGridModel'=>'[{name : ["ID", "Title", "Code", "Quantity"], width : [10,55,200,80]}]'
And that's why it did not work in javascript.
By the way, you can see that I wrote array in array. That is because with one array ZFDataGrid generates such javascript:
"subGridModel":{"name":["ID","Title","Code","Quantity"],"width":[10,55,200,80]}
instead of this:
"subGridModel":[{"name":["ID","Title","Code","Quantity"],"width":[10,55,200,80]}]
It is important for jqgrid subgrid to work!

Related

Zend 1.12 Zend/Form/Element -> addError() gives warning on line 2247 of Zend/FormI/Element

Environment:
Apache 2.4
Windows 8
PHP 5.4.14
Zend 1.12
I am doing a very very very simple action on my form, adding an error message on one of my elements with:
$form->getElement('elemetnid')->addError('error');
It works wonders for everyone else, but on my case it also gives out a warning that reads:
Warning: Invalid argument supplied for foreach() in ...\library\Zend\Form\Element.php on line 2247
This only happens when I try to set the error on my MultiSelect element, but if I do so on another element like Text, then everything is great and no warning is given. So I went to inspect the line on the warning, and realized that the problem is that "getValue()" for that element is returning "NULL" and that is not a correct value for the foreach loop inside the framework´s code. But how is that my responsability?
My question is, if anyone knows how to add an error message for a multiSelect without this warning popping up.
Thanks
I can't recreate your error with: Apache 2.2.16, Php 5.3.7 and Zf 1.12.5.
The behaviour is rather odd though. If I invalidate an element before validating the form (by adding an error to an element), it looks like it short circuits the form validation and the error message does not get applied to the form output.
If I try and force in an invalid value via the URL, a value not in my multi-select, I get repeat error messages, and my previously set error messages override the 'X' was not found in the haystack message.
$form = new Zend_Form;
$form->setMethod('GET');
$listOptions = array('one','two', 'three');
$select = new Zend_Form_Element_Multiselect('options', array(
'multiOptions' => $listOptions,
'validators' => array(
array('InArray',
false,
array(array_keys($listOptions)))
)
));
$submit = new Zend_Form_Element_Submit('submit', array(
'label' => 'Do something'
));
$form->addElements(array($select, $submit));
if(isset($_GET) && count($_GET)) {
if(true)
$select
->addError('The form will never validate.')
->addError('Two wrongs don\'t make a right.');
$form->isValid($_GET);
}
$form->setView(new Zend_View);
echo $form;
if ($form->isErrors()) {
echo 'Form did not validate';
var_dump($form->getErrors());
}

Zend_Cache_Frontend_Page does not recognize output without echo

I am trying to fiddle around with Zend_Cache, so I added following code to my action (will be moved to bootstrap later, I guess):
$frontendOptions = array(
'lifetime' => 7200,
'debug_header' => true, // für das Debuggen
'default_options' => array(
'cache' => true,
'cache_with_get_variables' => true,
'cache_with_session_variables' => true,
'cache_with_cookie_variables' => true,
'cache_with_post_variables' => true,
)
);
$backendOptions = array(
'cache_dir' => '/tmp/'
);
$cache = Zend_Cache::factory('Page', 'File',
$frontendOptions, $backendOptions
);
echo "hej";
var_dump($cache->start('someid'));
Zend generates a cache file containing hejbool(false) now, but apart from that it does not cache my page. According to a German book about zend framework, false is correct when there is no cache available. true is only returned when a cache was found.
When I debugged within Zend_Cache_Frontend_Page.php directly, it went down to the bottom of the start()-method, meaning that nothing went wrong (id given) and no cache was found, so one had to be generated. This was done (I can see it in /tmp/), but without the needed content.
So why does not not cache the output from Zend_View, but only direct output via echo?
I do not call any explicit function to render the view, but this did not seem necessary anymore (my views are always rendered automatically according to controller and action). I tried it for both a standard XHTML template (index.phtml) and an RSS template (index.rss.phtml).
Any ideas? Do you need any other code fragments?
When using the Zend_Cache_Frontend_Page you have to enable the disableOutputBuffering option. The reason is that Zend_Cache_Frontend_Page uses ob_start with a callback and it has to be the first call to ob_start otherwise it leads to that strange behaviour you've encountered.
To enable it you can either set it in your Bootstrap with
Zend_Controller_Front::getInstance()->setParam('disableOutputBuffering', true);
or using the configuration file after your frontController-setup (here in the INI-style configuration):
resources.frontController.params.disableOutputBuffering = true

Zend form in a popup (fancybox, lightbox....)

I am developping a web application using Zend and I ran out of ideas for a problem I am having. In just a few words, I am trying to have a contact form in a popup (Fancybox, lightbox, colorbox or whatever...). The whole thing works fine, in the sense that it shows up the contact form in the popup and allows to send emails. However, whenever there are errors (unfilled input or filled wrong), I couldn't get those errors to be displayed on the popup (it actually redirects me back to the form in a normal display (view+layout), to show the errors.
It is perhaps possible but I now thought that perhaps I could more easily bring my error message to a new popup (the contact page, filled unproperly, would lead to a error popup page...). I think this alternative could look cool but am having real trouble doing it. Now my real question is : Can we really make a form on a popup, using Facybox (Lighbox or any other actually ... just want my popup) and Zend? Any Guru outhere??
Thanks a lot
here is the code:
the link for instance:
<a class="popLink" href=" <?php echo $this->url(array('module'=>'default', 'controller'=>'contact', 'action'=>'sendmail')).'?ProID='.$this->proProfil->getProID(); ?>">Contact</a>
the action:
public function sendmailAction()
{
$this->_helper->layout()->setLayout('blank');
$request = $this->getRequest();
$proID = $this->_getParam("ProID");
$professionalsList = new Model_DirPro();
$proName = $professionalsList->getProInfo($proID);
$translate = Zend_Registry::get('translate');
Zend_Validate_Abstract::setDefaultTranslator($translate);
Zend_Form::setDefaultTranslator($translate);
$contactform = new Form_ContactForm();
$contactform->setTranslator($translate);
$contactform->setAttrib('id', 'contact');
$this->view->contactform = $contactform;
$this->view->proName = $proName;
if ($request->isPost()){
if ($contactform->isValid($this->_getAllParams())){
$mailSubject = $contactform->getValue('mailsubject');
if ($contactform->mailattcht->isUploaded()) {
$contactform->mailattcht->receive();
//etc....
the form:
class Form_ContactForm extends Zend_Form
{
public function init ()
{
$this->setName("email");
$this->setMethod('post');
$this->addElement('text', 'mailsubject',
array('filters' => array('StringTrim'),
'validators' => array(), 'required' => true, 'label' => 'Subject:'));
$mailattcht = new Zend_Form_Element_File('mailattcht');
$mailattcht->setLabel('Attach File:')->setDestination(APPLICATION_PATH.'/../public/mails');
$mailattcht->addValidator('Count', false, 1);
$mailattcht->addValidator('Size', false, 8000000);
$mailattcht->addValidator('Extension', false,
'jpg,png,gif,ppt,pptx,doc,docx,xls,xslx,pdf');
$this->addElement($mailattcht, 'mailattcht');
$this->addElement('textarea', 'mailbody',
array('filters' => array('StringTrim'),
'validators' => array(), 'required' => true, 'label' => 'Body:'));
$this->addElement('submit', 'send',
array('required' => false, 'ignore' => true, 'label' => 'Send'));
$this->addElement('hidden', 'return', array(
'value' => Zend_Controller_Front::getInstance()->getRequest()->getRequestUri(),
));
$this->setAttrib('enctype', 'multipart/form-data');
}
}
I would suggest implementing AJAX validation. This would allow for the form to be verified before it is submitted. ZendCasts has a good tutorial on how to accomplish this: http://www.zendcasts.com/ajaxify-your-zend_form-validation-with-jquery/2010/04/
Ajax requests are handled via the contextSwitch action helper. You can to specify the various contexts an action needs to handle (xml or json) in the init method of the controller as follows:
public function init()
{
$this->_helper->contextSwitch()
->addActionContext('send-mail', 'json')
->initContext()
;
}
The request url should contain a "format=json" appended to the query string. This will execute the action and send the response in json format. The default behaviour of JSON context is to extract all the public properties of the view and encode them as JSON. Further details can be found here http://framework.zend.com/manual/en/zend.controller.actionhelpers.html
I found a "probably not the prettiest" working solution, it is to indeed use ajax as mentioned in the previous zendcast for validation to stop the real validation (preventdefault), process the data return the result and if everything's ok restart it.

zend validator Zend_Validate_EmailAddress does nothing: site config looks OK, but probably isn't

Baffled again. (Zend Framework 1.11.1)
I've just added a validator to a VERY simple form, and nothing happens when invalid data is entered.
The code:
$form = new Zend_Form;
$form->setAction('/MyController/reponsepage')
->setMethod('post');
$form->setAttrib('id', 'firstTestForm');
$form->addElement('text', 'email', array('label' => 'EMail', 'value' => $this->_user['email']));
$form->addElement('hidden', 'expertID', array('value' => $_targetExpertID));
$form->addElement('submit', 'Submit and Be Free!');
$v = new Zend_Validate_EmailAddress();
$v->setMessage('Please enter a valid email address.');
$mailElem = $form->getElement('email')
->addValidator($v)
->setRequired(true);
$this->view->form = $form;
setRequired seems to do nothing. Leaving the field empty and hitting submit goes right through.
Garbage data also goes right through.
No error messages, nothing.
The library directory contains:
PATH_BLAH\library\Zend\Validate.php and
PATH_BLAH\library\Zend\Validate\ with all the normal stuff
It's sort of hard to guess what might be wrong.
I'd be much obliged for any clue that might come to your mind.
Thanks for reading.
Are you passing the data through to the form?
if ($this->getRequest()->isPost()
&& $form->isValid($this->getRequest()->getPost())) {
// process form
}
Phil Brown nailed it.
I had actually neglected to read back the post.
Head-slap here ...

codeigniter facebook

SORRY FOR THE LONG POST. I JUST WANT TO BE CLEAR!! :cheese:
I am using the stated template library in my ci setup and everything works great except for when i use Mr. Haughin's facebook_connect!
facebook_connect works beautifully if I call anything in a separate view file in my controller like so:
function facebookconnect()
{
$this->load->library('facebook_connect');
$data = array(
'user' => $this->facebook_connect->user,
'user_id' => $this->facebook_connect->user_id
);
$this->template->write_view('content','fbtest',$data);
$this->template->render();
}
this works no problem calling it from it's own page and everyone is happy. But when I try to put my facebook interactivity into a div on my homepage with this code:
function index()
{
$this->load->library('facebook_connect');
$data = array(
'user' => $this->facebook_connect->user,
'user_id' => $this->facebook_connect->user_id
);
$this->template->write_view('content','indexpage',$data);
$this->template->render();
}
My homepage loads fine but I have this error:
A PHP Error was encountered
Severity: Notice
Message: Undefined variable: user_id
Filename: views/indexpage.php
Line Number: 32
This i think is strange as it works with code above. My variables are passed so I don't get it.
What I want to achieve is that on the homepage a list of facebook friends should appear when page loads. Is there anything i should know about this library? I went through the userguide looking for to see if i could write a separate view to the div that should carry the facebook connect results. Here is my view code just incase it will help:
php if ( !$user_id ):
php else:
" />
Hi php$user['first_name']!
(Logout)
php endif;
Here's some comments!
[removed]
FB.init("$this->config->item('facebook_api_key')", "/xd_receiver.htm");
[removed]
The problem seems to be in this line:
user_id' => $this->facebook_connect->user_id
because facebook's PHP client doesn't have any user_id property. The user id is available from:
user_id' => $this->facebook_connect->user
So try removing the line:
'user_id' => $this->facebook_connect->user_id