Including '0' in numberArray dropdown - php

Is it possible to include the option '0' in a dropdown generated by:-
'options' => Mage::helper('menu')->numberArray(5,Mage::helper('menu')->__('')),
This is part of...
$fieldset->addField('column', 'select', array(
'name' => 'column',
'label' => Mage::helper('menu')->__('Column'),
'title' => Mage::helper('menu')->__('Column'),
'required' => true,
'options' => Mage::helper('menu')->numberArray(5,Mage::helper('menu')->__('')),
));
Which generates a dropdown 1-5 but I'm wanting to include 0 at the beginning of this dropdown (or 'none' or anything other value that isn't an integer of 1+) but I'm unsure how to edit the above to allow this.
If anyone could advise what is needed please, that would be great.
Thanks in advance.

Since numberArray() is not a native Magento method, we can't know what this custom method really does in the end.
But, Varien_Data_Form_Element_Fieldset::addField() usually expects just a simple assoc array as value for the options key, so most probably something like this will work:
'options' => array(
0 => 'none',
1 => 'one',
2 => 'two',
3 => 'three',
4 => 'four',
5 => 'five'
),

Related

How to get a checbox checked in cakePHP 4

So i have a checkbox and i need certain values to be checkd i tried to do this and is not working
$columnas = [
1 => 'Columna 1',
2 => 'Columna 2',
3 => 'Columna 3',
4 => 'Columna 4',
5 => 'Columna 5',
6 => 'Columna 6',
7 => 'Columna 7'
];
$columnas_actuales = [
1 => 3,
2 => 5,
3 => 7,
];
<?= $this->Form->control('cliente_configuracion.columnas_visibles', [
'options' => $columnas,
'selected' => $columnas_actuales,
'multiple' => 'checkbox',
'label' => false,
'templates' => [
'checkbox' => '<input type="checkbox" name="{{name}}" value="{{value}}"{{attrs}}>',
'checkboxFormGroup' => '{{label}}',
'checkboxWrapper' => '<div class="form-check form-check-inline">{{label}}</div>',
]
])
$columnas_actuales is the array that contains the selected options but for some reason they are not being checked.
in new in cake and in php so i dont know if im doing something wrong.
Thanks !!
Edit: I added an example of the $columnas_actuales variable.
Your data looks correct, however there is no selected option. The options to pre-select values are called default and value, where the former can be overwritten by request/context data (for example when a user changes the selection and submits the form), and the latter will always fix the selected values.
So you'd probably want to use default:
'default' => $columnas_actuales,
See also
Cookbook > Views > Helpers > Form > Common Options For Specific Controls

TYPO3 (7.6.14) Extbase TCA: Field missing in mask after setting foreign_sortby

After I set the 'foreign_sortby' => 'datum'; this field is missing now at my edit mask. Does anybody know why?
TCA of tx_veranstaltungen_domain_model_terminblock (1 terminblock can have multiple termine)
'termine' => array(
'exclude' => 1,
'label' => 'LLL:EXT:veranstaltungen/Resources/Private/Language/locallang_db.xlf:tx_veranstaltungen_domain_model_terminblock.termine',
'config' => array(
'type' => 'inline',
'foreign_table' => 'tx_veranstaltungen_domain_model_termin',
'foreign_field' => 'terminblock',
'foreign_sortby' => 'datum',
'maxitems' => 9999,
'appearance' => array(
'collapseAll' => 0,
'levelLinksPosition' => 'top',
'showSynchronizationLink' => 1,
'showPossibleLocalizationRecords' => 1,
'useSortable' => 1,
'showAllLocalizationLink' => 1
),
),
),
Okay I found it out whats the problem, after reading Bug report
You should use foreign_default_sortby instead of foreign_sortby, because IRRE hides the field you use for sorting. The dangerous thing is, that the field could be overwritten by "sorting values". So I wondered why all my fields (of type date (timestamp)) has the value 01.01.1970... because the field values changed to 1,2,....
I hope this can help others, before they destroy their data. :)
(I'm using Typo3 7.6.14)

PHP Zend 2 Framework show Textarea

I'm creating a form using Zend2 framework, and can't figure out why a simple Textarea is not showing up on the view (below you can see my code). I've tried the type Text and it shows a standard single lined text field, but got luck with Textarea. I've also tried a non existing type, and zend throws an exception, so it seems Textarea type actually exists, and I must be missing a mandatory param or something like that. Could anyone point me in the right direction?
$this->add(array(
'type' => 'Zend\Form\Element\Textarea',
'name' => 'pincodes',
'options' => array(
'label' => 'Pincodes (uno por línea)',
),
'attributes' => array(
'rows' => '10',
'cols' => '75',
)
));
SOLVED
My bad, it looks there was an intermediate layer in the project ignoring all the Textarea fields.
I just check you code and found 2 things missing first
use Zend\Form\Element;
use Zend\Form\Form;
Which I think you have used in you file.
Another mistake was you were missing comma in the code. use this below code.
$this->add(array(
'type' => 'Zend\Form\Element\Textarea',
'name' => 'pincodes',
'options' => array(
'label' => 'Pincodes (uno por línea)',
),
'attributes' => array(
'rows' => '10',
'cols' => '75',
),
));
Good luck
Try changing your 'rows' and 'cols' value from a string to integer (remove single quotes).
'attributes' = > array(
'rows' => 10,
'cols' => 75,
);

CakePHP: Retrieving data

I'm stuck in retrieving some sort of data in my view. I have to list information of a certain "Job", which has different attributes already stored in the database.
For example, I'd like to get the field of 'weighting' listed.
The debug($this->viewVars) prints me this (which represents what's stored in the DB):
'JobValues' => array(
(int) 0 => array(
'id' => '1',
'yearly_job_id' => '1',
'institution_type_id' => '1',
'norm_rate' => '5',
'weighting' => '5.00',
'standard_value' => '5.00',
'education_weeks' => '5.0',
'group_distribution' => '0.50',
'YearlyJob' => array(
'id' => '1',
'year_id' => '1',
'job_id' => '1',
'full_time_jobs_needed' => true,
'education_count_needed' => true,
'is_care' => true
),
Normally I would just print this: echo([JobValue][weighting]);, but there is a number in between, so echo([JobValue][1][weighting]); won't lead to success. What could I implement in my view (or model)? Any advice is highly appreciated.
For printing out the data, if there's only one top level of array, just remove it. print_r(array_shift($foo['JobValues']['weighting']));
If there are multiple arrays on the same level, you need to do a foreach to iterate into each one of the record.

How can I initialize Zend_Form_Element_Select with a config array?

I tried:
$form->addElement(
'select',
'salutation',
array(
'required' => true,
'options' => array(
'Mr.' => 'Mr.',
'Mrs.' => 'Mrs.',
'Ms.' => 'Ms.',
),
)
);
Then I print_r()ed the form, and options for salutation are empty. Does anybody know the correct spell for that? As far as I see, there's no documentation for Zend element configs' format.
You should use 'multiOptions' instead of 'options'.

Categories