Two form groups, two tabs in last group - sonata-admin

Here is my code:
$formMapper
->with('Order', [
'class' => 'col-md-6'
])
->add('customer')
->end()
->with('Activity', [
'class' => 'col-md-6'
])
->add('poNumber')
->end()->end()
->tab('Test')
How do I keep the two groups - but the second group needs two or more tabs?
EDIT | The above is adding two tabs "Default" and "Test" with "Default" showing the two groups...

Related

Cakephp contain inside another. It´s possible?

I am trying to make a cotain inside another. it's possible?
$tareasp = $this->ProyectosCategoriasTareas
->find('all',
['contain' =>
['Tareas'=>
['contain'=>
['Photos']
]
]
])
->where(['proyecto_id' => $proyecto['id']]);
I tried it but not work
You don't need to use the contain key multiple times, you can just nest the names:
'contain' => [
'Tareas' => [
'Photos'
]
]
or use dot notation:
'contain' => [
'Tareas.Photos'
]
See also
Cookbook > Database Access & ORM > Query Builder > Loading Associations

CakePHP pagination, how do I sort by the count of a contained model?

Using CakePHP 2.3, I'm retrieving data using a paginator. So, say my models are Countries having many Cities, and in my CountryController I have...
$this->Paginator->settings = [
'fields' => [
'id'
'country_name'
],
'contain' => [
'City' => [
'id'
'city_name',
'conditions' => [
'population >' => 1000000;
]
]
]
];
...which gets me a list of all counties with each row containing a list of any populous cities.
In the view I am obviously able to iterate foreach ($cities as $city) and echo $country['country_name'] etc. and also if I wish I can show a count of the contained cities by echoing count($country['City']).
Using the paginator I can sort the country results by passing back a field name in the query string, e.g. sort=country_name, but how can I get the results to sort by the count of the contained cities?
It is unfortunately not possible to sort by the count of the hasMany Table using the custom Cakephp Pagination. Your best bet is to use counterCache as described in the Docs.
You will need to have a field in country table, named as city_count. This field will be updated in the Country Table automatically by Cakephp whenever there is a save operation on city table.
Since you only want to count the cities with population > 100K. You can specify the condition in counterScope which will only update the column when condition is met.
This can be defined in your City Model as below:
class City extends AppModel {
public $belongsTo = array(
'Country' => array(
'counterCache' => true,
'counterScope' => array(
'City.population > ' => 1000000
)
)
);
}

Validation array

I have a tags in my project but tags is created by me and user can checked what he want. It works correctly but I have a problem with Validation. In my store function I have an array and I want to validate any single element. I wrote this validate rule:
$validator = Validator::make($request->tags, [
'id' => 'integer|max:15'
]);
It doesn't work. Why?
You may use this
[
'tags' => 'array',
'tags.*' => 'integer|max:15'
]

Show custom field in query list in cakephp3

I want to create a dropdown with custom field but my list query append id field into the query. How to show only selected fields in my query.
$this->loadModel('CardTypes');
$cardTypes = $this->CardTypes->find('list')->select(['code', 'name']);
In my view
$this->Form->select('card_type_id', $cardTypes, [ 'default' => 'DELTA']);
see the manual
$cardTypes = $this->CardTypes->->find('list', [
'keyField' => 'code',
'valueField' => 'name'
]);

CakePHP 3 hasMany update strange behaviour

I have JobsTable:
This is relation definition:
$this->hasMany( 'JobContracts', [
'foreignKey' => 'job_id'
] );
Saving code:
$entity = $this->patchEntity( $entity, $toSave, [
'fieldList' => ['notes],
'associated' => [
'JobContracts' => ['fieldList' => ['id', 'checked']]
]
] );
And now:
if I put this notes in fieldList then JobContracts are NOT saved properly.
If I remove fieldList, then I am able to save it properly.
Question is Why? I need to control base model fields also. Any suggestions?
Ive already checked: http://book.cakephp.org/3.0/en/orm/saving-data.html#avoiding-property-mass-assignment-attacks
You need to allow assigning the association property too, not only notes. If you don't, then the associated data is never going to be set on the resulting entity, and consequently is not going to be saved.
Check the docs that you've linked again, the tags example shows exactly that:
// Only allow changing the title and tags
// and the tag name is the only column that can be set
$entity = $this->patchEntity($entity, $data, [
'fieldList' => ['title', 'tags'],
'associated' => ['Tags' => ['fieldList' => ['name']]]
]);
$this->save($entity);
http://book.cakephp.org/3.0/en/orm/saving-data.html#avoiding-property-mass-assignment-attacks
So, add job_contracts to the field list, and you should be good.

Resources