cakephp ->set() a value in an object - cakephp

I can use the cakephp set() to add a value in an object at the top level but I also need to set a value for an object inside the object and I can seem to access it. Is this possible?
I need to add business_id inside the employee object.
I though I might use $user->set->employee('business_id', '1'); but I get an error on the employee part.
object(App\Model\Entity\User) {
'email' => 'dfgdfg#sdfsdf.com',
'new_password' => 'ttt',
'confirm_password' => 'ttt',
'employee' => object(App\Model\Entity\Employee) {
'name' => 'dsfsfsdfsfd',
'email' => 'sdfsdfsdf#sdfsdf.com',
'surname' => 'sdfsdfsdfsdf',
'employee_num' => 'sdfsdfsdfsd',
'[new]' => true,

I tried it a couple of different ways and I got it work by $user->employee->set('business_id', '1');

Related

Paginate and Sort bug(s)?

In my controller I have my pagination set to order by 2 fields.
public $paginate = [
'limit' => 50,
'order' => ['first_name', 'last_name']
];
$contacts = $this->paginate($this->Contacts);
This works fine on the first page, but since I left out the default direction => 'ASC' the Paginator links don't work at all:
/contacts?page=2&sort=0&direction=first_name
When I add in the direction, it works, but of course only sorts by the first field, messing up the sort order.
/contacts?page=2&sort=Contacts.first_name&direction=ASC
Should the default direction be explicitly required?
Is there a method to maintain both fields for sorting during pagination?
Sorting by virtual fields (e.g. full_name => first_name . ' ' . last_name) doesn't work as it did in 2.x
Solved both issues with the following:
Set the default sort order to be the same as the virtual field:
public $paginate = [
'order' => ['first_name', 'last_name']
];
Then just add the following to the View to prevent the paginator from overriding the default order unless specified by the user:
if (empty($_GET['direction'])) { $this->Paginator->options(['url' => ['direction' => null, 'sort' => null]]); }

hook_action_info does not create its VBO list item in view

I am trying to code my custom action using views and VBO.
The my view shows the user a list of commerce line items.
Here the code:
function nlmcode_action_info() {
return array(
'vbo_download_pdf' => array(
'type' => 'entity',
'label' => t('Download PDF'),
'configurable' => FALSE,
'triggers' => array('any')
),
);
}
function vbo_download_pdf($entity, $context) {
dpm("Do the magic here.");
}
I then can see the bulk operation available in the select field but once I have selected my custom 'Download PDF' option and added to the view, the item is missing in the VBO drop down list.
Solved.
Permissions to 'Download PDF' have to be set.

Laravel 5.2 seed specific data array

I am trying to seed my database with some specific content to get my application started. I am aware of Faker and how to use it (which I do for my Users). Now I want to fill a table with (alot) of records that are not randomly generated, so not created by Faker.
For example I want to have a table with some (lets say 30) clubs so that I can generate a few hundered users who are member of one of those 30 clubs with $faker->randomElement.
Is there another way then to type this 30 times?
$club = Club::create(array(
'name' => 'FC Barcelona',
'number' => '001',
));
Couldn't find this in the laravel (5.2) docs. Only the Faker is explained.
Thanks
What you can do is creating one array with clubs and seed them and in UsersDatabaseSeeder you can create in loop as many records you want and assign for each of them random club.
EDIT
$clubs = [['prop1'=> 'val1',], ['prop1' => 'val2']];
\DB::table('clubs')->insert($clubs);
Content::create(array(
'content_title' => 'Swiss Army Man',
'content_link' => 'www.Youtube.com',
'description' => 'This movie is .....',
'content_title' => 'Movie',
'image_path' => 'images/m1.jpg',
'year' => '2014-12-4'
));
Content::create(array(
'content_title' => 'Me Before You',
'content_link' => 'www.Youtube.com',
'description' => 'asdddddd',
'content_title' => 'Movie',
'image_path' => 'images/m2.jpg',
'year' => '2016-6-4'
));
,,, So You can create as many as u want ;)

symfony1 multiple checkboxes require all

I want to require all checkboxes in the set
My code looks like this:
$this->widgetSchema['consent_confirmation'] = new sfWidgetFormSelectCheckbox(
array(
'choices' => Doctrine_Core::getTable('MyTable')->getOptions(),
)
);
UPDATE:
My validation looks like this:
$this->validatorSchema['consent_confirmation'] = new sfValidatorChoice(array(
'choices' => array(Doctrine_Core::getTable('MyTable')->getOptions()),
'multiple' => true,
'required' => true
));
How can I make it return 'Required' if they're not all checked, and be valid if they're all checked?
My symfony 1.* memory is very hazy at this point but I think what you need to do here is add a rule to the validatorSchema to handle validation of this widget.
According to the Validation Appendix the validator you need is sfValidatorChoice.
This widget has a number of options, including:
multiple
min
max
Assuming that you have two options as above, and you want to enforce selecting both, I'm guessing that you might need to add the following to your form's configure() method:
public function configure()
{
$this->widgetSchema['consent_confirmation'] = new sfWidgetFormSelectCheckbox(array(
'choices' => array(
'1' => 'Yes I agree to #1',
'2' => 'Yes I agree to #2',
)),
);
$this->validatorSchema['consent_confirmation'] = new sfValidatorChoice(array(
'multiple' => true,
'min' => 2,
'max' => 2,
));
}
Something like that - I'm not sure about the assignment to the validatorSchema to be honest, there might be something like addValidator() or setValidator()methods instead. EDIT: I think there were some helper methods added, but some of these might be 1.4 specific. The above assignment should work either way...
Hope this helps :)

How to change the separators for Cakephp Form Helper for multiple checkboxes

I'm generating a bunch of checkboxes through the Form Helper.
Essenciatially I have an array with like $tests = array
$tests = array(1 => 'test', 15=>'test2');
Then I can use it like this
echo $this->Form->input('test_id', array(
'type' => 'select',
'multiple' => 'checkbox',
'div' => false,
'before' => '<li>',
'after' => '</li>',
'separator' => '</li> <li>'));
I expected it would use the div => false to take off the div of every checkbox but it only applies the options to the exterior block. Is there anyway to change all the blocks from <div class=>'checkbox'> to <li class='anything else'>
Just look at the fields it produces, then write your own simple foreach() loop and write them yourself in whatever wrapping element(s) you want.
I forget whether it's possible with Cake or not, but don't think it is. The above is what we've done before - because it's simple to write, it took us less time to write than it did to look further into it :)

Resources