How to create a ZF2 FormCollection of the Doctrine ORM Module's ObjectSelect elements? - orm

I have an odd situation where my add form works perfectly, but the edit form will not even load. Instead I get the following error:
Notice: Undefined property: DoctrineModule\Form\Element\ObjectSelect::$object in /vendor/zendframework/zendframework/library/Zend/Form/Element/Collection.php on line 517
Fatal error: Class name must be a valid object or a string in /vendor/zendframework/zendframework/library/Zend/Form/Element/Collection.php on line 517
I have objects of the class Application\Model\Record which have a many-to-many relationship to objects of the class Application\Model\Subject. I want the Subjects to appear as dropdowns in the Record forms, with the option to add multiple Subjects. So in the RecordFieldset.php I have:
$this->add(array(
'name' => 'subjects',
'type' => 'Zend\Form\Element\Collection',
'options' => array(
'label' => 'Subjects',
'count' => 1,
'should_create_template' => true,
'allow_add' => true,
'allow_remove' => true,
'template_placeholder' => '__subjectindex__',
'target_element' => array (
'name' => 'subject',
'type' => 'DoctrineModule\Form\Element\ObjectSelect',
'options' => array(
'object_manager' => $this->objectManager,
'target_class' => 'Application\Model\Subject',
'property' => 'name',
'empty_option' => 'Select a subject',
),
'attributes' => array(
'class' => 'form-control',
),
),
),
));
And like I said, this works perfectly in the Record add form. But it looks like on the edit form it cannot load the Subjects. Has anyone else tried something like this? Or do you have an idea what the error is saying?
Environment:
Zend Framework 2.3.3
Doctrine-orm-module 0.8.0
Doctrine 2.4.2

Looks like this is a bug on ZF2, target elements need to be a fieldset for it to work otherwise it will run into this issue. Use a fieldset to wrap the ObjectSelect.

Related

Where can i find a full list of InputeFilters Zend2 properties?

Where i can find a complit list of validator construction properties (factory). For exmple we got 1 inputeFilter 'email':
$this->add(array(
'name' => 'email',
'required' => true,
'validators' => array(
array(
'name' => 'EmailAddress',
'options' => array(
'domain' => true,
),
),
),
));
May be some documentation with all properties ('name', 'requiered. e.t.c.) and their structure.
they are all well documented just not in the array notation http://framework.zend.com/manual/current/en/modules/zend.validator.set.html
also you can view the invokables in the vendor code the variable is called $invokableClasses.
..\vendor\zendframework\zendframework\library\Zend\Validator\ValidatorPluginManager.php
For options you may still look at the documentation since they obviously vary from validator to validator.
Edit: In some cases building the validator out of the array notation is helpful. You'll just have to add them into the inputfilter notation like so:
...
$eanValidator = new Zend\Validator\Barcode(array(
'adapter' => 'EAN13',
'checksum' => false,
));
...
$this->add(array(
'name' => 'ean-test',
'required' => true,
'validators' => array(
array(
$eanValidator,
$someOtherValidator,
...
),
),
));

How to edit column in CGridView

How is it possible, to make the columns in CGridView editable? i searched and find several extensions, but nothing works for me.
i'm doing something wrong or the extensions are buggy, i don't know.
can anyone help me please, and describe exactly, what i have to do, to make my columns in CGridView editable?
Yii-booster extension has class TbEditableColumn that implements column edit feature. You can look example here. There is my example of code:
array(
'class' => 'YbEditableColumn',
'name' => 'priority',
'value' => '$data->priorityName',
'sortable' => false,
'editable' => array(
'type' => 'select',
'source' => Task::model()->getPriorities(),
'url' => $this->createUrl('update'),
'placement' => 'top',
)
),
There is other extensions based on bootstrap Editable, like this, may be you can check it too.

CClientScript duplicates the output

I'm trying to use this extension in a partial view, in my registration module...
$form->widget('ext.tokenInput.TokenInput', array(
'model' => $model,
'attribute' => 'tags',
'url' => array('wizard/search'),
'options' => array(
'allowCreation' => false,
'preventDuplicates' => true,
'allowFreeTagging' => false,
'minChars' => 2,
'theme' => 'facebook',
)
));
...and assets (javascript and CSS files) are duplicated.
Basically I can see in the HTML code multiple occurrences of these files.
I have the same problem if I try to add custom JS files in the same partial view.
I specify POS_HEAD and I can see the code in <head> and in the middle of the page.
Why CClientScript duplicates assets if I add them in a partial view?
Thanks a lot!

Customize getting data from SugarCRM Custom Module by Query parameter in rest api

Hi I'm trying to get data from SugarCRM by REST api. It's fine with default module, but with custom module, I got a issue.
I used this example
And getting data from Contacts module which has last name = "abc" is ok with these code:
$get_entry_list_parameters = array(
'session' => $session_id,
'module_name' => 'Contacts',
'query' => "contacts.last_name='abc'",
'order_by' => "",
'offset' => '0',
'select_fields' => array(
'id'
),
'link_name_to_fields_array' => array(
),
'max_results' => '1',
'deleted' => '0',
'Favorites' => false,
);
When I tried to get data from our custom module (eg: Event Session inside Event package), so it's ok as well without Query param like these code
$get_entry_list_parameters = array(
'session' => $session_id,
'module_name' => 'event_event_session',
'order_by' => "",
'offset' => '0',
'select_fields' => array(
'id',
'name'
),
'link_name_to_fields_array' => array(
),
'max_results' => '3',
'deleted' => '0',
'Favorites' => false,
);
But after that I put Query param, I got no record
$get_entry_list_parameters = array(
'session' => $session_id,
'module_name' => 'event_event_session',
'query' => "event_event_session.name='def'",
'order_by' => "",
'offset' => '0',
'select_fields' => array(
'id',
'name'
),
'link_name_to_fields_array' => array(
),
'max_results' => '3',
'deleted' => '0',
'Favorites' => false,
);
I think the way I used to get data from custom module is not correct.
Anyone can help me resolve this issue. Thank you!
Johnny
Are you sure the table name for the custom module is "event_event_session"?
When we create any new custom module using module builder then it is asking for key name. So our module will become as key_modulename. So make sure you are passing the key name along with module name. So that way you can access the data of custom new module.

Error with dijit.form.NumberTextBox

Despite many trials and errors, I cannot get the NumberTextBox widget to work. I keep receiving this error message:
Catchable fatal error: Argument 4 passed to Zend_Dojo_View_Helper_NumberTextBox::numberTextBox() must be an array, null given
The odd thing is: I event tried this example straight from the ZF examples page and it failed with the same error
->addElement(
'NumberTextBox',
'numberbox',
array(
'label' => 'NumberTextBox',
'required' => true,
'invalidMessage' => 'Invalid elevation.',
'constraints' => array(
'min' => -20000,
'max' => 20000,
'places' => 0,
)
)
)
So, I'm at a loss now. If someone has the time to look at the code found here, your help would be greatly appreciated. I know it's something that I'm overlooking. It always is.
If you are setting decorators, make sure you change ViewHelper to DijitElement. I ran into this problem and that was the cause.
Shot in the dark: try getting rid of the ',' at the end of 'places' => 0,'
I use a base Form,
BaseForm extends Zend_Dojo_Form{
public $elementDecorators = array(
'DijitElement',
array(
array('data' => 'HtmlTag'),
array('tag' => 'div', 'class' => 'element')
),
array('Label',
array('tag' => 'div', 'class' => 'element-label')
),
array(array('row' => 'HtmlTag'),
array('tag' => 'div', 'class' => 'element-row' )
)
);
... init(){}
.... construct(){}
}
MyForm extends BaseForm{
constructor(){
$this->starts = new Zend_Dojo_Form_Element_DateTextBox( "starts" );
$this->starts->setLabel('Starting from')
->setDecorators($this->elementDecorators);
}
}
I made the source code as simple as possible, to depict the idea of what I mean.