Re: Saving data to Has Many relationship table from single form in CakePHP 3

2014-08-05 Thread Jipson Thomas
Hi Jose,
Yes , I did the controller, model and view creation through the bake 
console. But it is not helping me to save data from single form to multiple 
tables. In my case the vendor signup form is having the input  fields to 
vendor table, vendor manager table and a user table. Would you please help 
me to find a solution on this?

Regards,
Jipson

On Monday, 4 August 2014 18:26:48 UTC+1, José Lorenzo wrote:

 I would recommend that you use the bake console tool to create the initial 
 controller code and forms, that way I'm sure you will learn and understand 
 how forms should be structured.

 On Monday, August 4, 2014 5:46:29 PM UTC+2, Jipson Thomas wrote:

 Hi,
 When I change the controller code as follows, It saves in vendor table 
 only and return a true value.

 $vendors = TableRegistry::get('Vendors');
 
 if ($this-request-is('post')) {
 $vendor = new Vendor($this-request-data['Vendor']);
 $vendor-VendorManagers = [
 new VendorManager($this-request-data['VendorManager']),
 ];
 $vendor-Users = [
 new User($this-request-data['User']),
 ];
 //print_r($vendor);
 if ($vendors-save($vendor)) {
 $this-Flash-success(__('The vendor has been saved'));
 return $this-redirect(['action' = 'index']);
 }
 $this-Flash-error(__('Unable to add the vendor'));
 }
 $this-set('vendor', $vendor);
 $this-set('subscription_package', $id);
 $this-set('subscription_type', $payoption);

 On Monday, 4 August 2014 16:17:10 UTC+1, Jipson Thomas wrote:

 The save method is returning a false only not any error messages.

 On Monday, 4 August 2014 14:43:20 UTC+1, Jipson Thomas wrote:

 Hi All,
 Would you please give me some details or samples of saving data from a 
 single form to the tables main and has many relationships. I tries with 
 the 
 normal way by adding a modelname.fieldname on form and the sual newentity 
 of main table but it through false on save(); Please help me to fix this

 Regards,
 Jipson



-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.


Re: Saving data to Has Many relationship table from single form in CakePHP 3

2014-08-05 Thread José Lorenzo
I find hard to believe that the form you showed above was generated by 
bake, but I can definitely look if there is any errors in the bake tool. 
The reason I say that is that we are not using the 'UppercaseThing.field' 
notation anymore, we use lowercase properties.
For example if Articles belongsTo Authors the form would look like:

 ?php echo $this-Form-input('title') ?
 ?php echo $this-Form-input('author.name') ?
 ?php echo $this-Form-input('author.email') ?

On Tuesday, August 5, 2014 10:48:56 AM UTC+2, Jipson Thomas wrote:

 Hi Jose,
 Yes , I did the controller, model and view creation through the bake 
 console. But it is not helping me to save data from single form to multiple 
 tables. In my case the vendor signup form is having the input  fields to 
 vendor table, vendor manager table and a user table. Would you please help 
 me to find a solution on this?

 Regards,
 Jipson

 On Monday, 4 August 2014 18:26:48 UTC+1, José Lorenzo wrote:

 I would recommend that you use the bake console tool to create the 
 initial controller code and forms, that way I'm sure you will learn and 
 understand how forms should be structured.

 On Monday, August 4, 2014 5:46:29 PM UTC+2, Jipson Thomas wrote:

 Hi,
 When I change the controller code as follows, It saves in vendor table 
 only and return a true value.

 $vendors = TableRegistry::get('Vendors');
 
 if ($this-request-is('post')) {
 $vendor = new Vendor($this-request-data['Vendor']);
 $vendor-VendorManagers = [
 new VendorManager($this-request-data['VendorManager']),
 ];
 $vendor-Users = [
 new User($this-request-data['User']),
 ];
 //print_r($vendor);
 if ($vendors-save($vendor)) {
 $this-Flash-success(__('The vendor has been saved'));
 return $this-redirect(['action' = 'index']);
 }
 $this-Flash-error(__('Unable to add the vendor'));
 }
 $this-set('vendor', $vendor);
 $this-set('subscription_package', $id);
 $this-set('subscription_type', $payoption);

 On Monday, 4 August 2014 16:17:10 UTC+1, Jipson Thomas wrote:

 The save method is returning a false only not any error messages.

 On Monday, 4 August 2014 14:43:20 UTC+1, Jipson Thomas wrote:

 Hi All,
 Would you please give me some details or samples of saving data from a 
 single form to the tables main and has many relationships. I tries with 
 the 
 normal way by adding a modelname.fieldname on form and the sual newentity 
 of main table but it through false on save(); Please help me to fix this

 Regards,
 Jipson



-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.


Re: Saving data to Has Many relationship table from single form in CakePHP 3

2014-08-05 Thread Jipson Thomas
Hi Jose,
Sorry. What I said in my last thread that I re created my models ,views and 
controllers through bake (The code I pasted in an older thread was not from 
bake command.). The form created through bake doesn't include the user 
table inputs. I will paste the code of form generated through bake below.
===

div class=vendors form
?= $this-Form-create($vendor); ?
fieldset
legend?= __('Add Vendor'); ?/legend
?php
echo $this-Form-input('company_name');
echo $this-Form-input('logo_url');
echo $this-Form-input('email_domain');
echo $this-Form-input('phone');
echo $this-Form-input('fax');
echo $this-Form-input('website');
echo $this-Form-input('address');
echo $this-Form-input('country');
echo $this-Form-input('city');
echo $this-Form-input('state');
echo $this-Form-input('postalcode');
echo $this-Form-input('subscription_package');
echo $this-Form-input('status');
echo $this-Form-input('no_emails');
echo $this-Form-input('no_partners');
echo $this-Form-input('coupon_id');
echo $this-Form-input('language');
?
/fieldset
?= $this-Form-button(__('Submit')); ?
?= $this-Form-end(); ?
/div
div class=actions
h3?= __('Actions'); ?/h3
ul
li?= $this-Html-link(__('List Vendors'), ['action' = 
'index']); ?/li
li?= $this-Html-link(__('List Coupons'), ['controller' = 
'Coupons', 'action' = 'index']); ? /li
li?= $this-Html-link(__('New Coupon'), ['controller' = 
'Coupons', 'action' = 'add']); ? /li
li?= $this-Html-link(__('List Partners'), ['controller' = 
'Partners', 'action' = 'index']); ? /li
li?= $this-Html-link(__('New Partner'), ['controller' = 
'Partners', 'action' = 'add']); ? /li
li?= $this-Html-link(__('List VendorManagers'), ['controller' 
= 'VendorManagers', 'action' = 'index']); ? /li
li?= $this-Html-link(__('New Vendor Manager'), ['controller' 
= 'VendorManagers', 'action' = 'add']); ? /li
/ul
/div

==

The above code is to create separate forms for each table. My requirement 
is to make a single signup form for all the 3 tables.

Apologize to be a continuing burdan...

Regards,
Jipson


On Tuesday, 5 August 2014 10:11:36 UTC+1, José Lorenzo wrote:

 I find hard to believe that the form you showed above was generated by 
 bake, but I can definitely look if there is any errors in the bake tool. 
 The reason I say that is that we are not using the 'UppercaseThing.field' 
 notation anymore, we use lowercase properties.
 For example if Articles belongsTo Authors the form would look like:

  ?php echo $this-Form-input('title') ?
  ?php echo $this-Form-input('author.name') ?
  ?php echo $this-Form-input('author.email') ?

 On Tuesday, August 5, 2014 10:48:56 AM UTC+2, Jipson Thomas wrote:

 Hi Jose,
 Yes , I did the controller, model and view creation through the bake 
 console. But it is not helping me to save data from single form to multiple 
 tables. In my case the vendor signup form is having the input  fields to 
 vendor table, vendor manager table and a user table. Would you please help 
 me to find a solution on this?

 Regards,
 Jipson

 On Monday, 4 August 2014 18:26:48 UTC+1, José Lorenzo wrote:

 I would recommend that you use the bake console tool to create the 
 initial controller code and forms, that way I'm sure you will learn and 
 understand how forms should be structured.

 On Monday, August 4, 2014 5:46:29 PM UTC+2, Jipson Thomas wrote:

 Hi,
 When I change the controller code as follows, It saves in vendor table 
 only and return a true value.

 $vendors = TableRegistry::get('Vendors');
 
 if ($this-request-is('post')) {
 $vendor = new Vendor($this-request-data['Vendor']);
 $vendor-VendorManagers = [
 new 
 VendorManager($this-request-data['VendorManager']),
 ];
 $vendor-Users = [
 new User($this-request-data['User']),
 ];
 //print_r($vendor);
 if ($vendors-save($vendor)) {
 $this-Flash-success(__('The vendor has been saved'));
 return $this-redirect(['action' = 'index']);
 }
 $this-Flash-error(__('Unable to add the vendor'));
 }
 $this-set('vendor', $vendor);
 $this-set('subscription_package', $id);
 $this-set('subscription_type', $payoption);

 On Monday, 4 August 2014 16:17:10 UTC+1, Jipson Thomas wrote:

 The save method is returning a false only not any error messages.

 On Monday, 4 August 2014 14:43:20 UTC+1, Jipson Thomas wrote:

 Hi All,
 Would you please give me some details or samples of saving data from 
 a single form to the tables main and has many relationships. I tries 
 with 
 the normal way by adding a modelname.fieldname on form and the sual 
 newentity of main table but it through false on save(); Please help me 
 to 

Re: Saving data to Has Many relationship table from single form in CakePHP 3

2014-08-05 Thread José Lorenzo
Do as I told you in my previous message: input('related_propery.field')

On Tuesday, August 5, 2014 11:19:29 AM UTC+2, Jipson Thomas wrote:

 Hi Jose,
 Sorry. What I said in my last thread that I re created my models ,views 
 and controllers through bake (The code I pasted in an older thread was not 
 from bake command.). The form created through bake doesn't include the user 
 table inputs. I will paste the code of form generated through bake below.
 ===

 div class=vendors form
 ?= $this-Form-create($vendor); ?
 fieldset
 legend?= __('Add Vendor'); ?/legend
 ?php
 echo $this-Form-input('company_name');
 echo $this-Form-input('logo_url');
 echo $this-Form-input('email_domain');
 echo $this-Form-input('phone');
 echo $this-Form-input('fax');
 echo $this-Form-input('website');
 echo $this-Form-input('address');
 echo $this-Form-input('country');
 echo $this-Form-input('city');
 echo $this-Form-input('state');
 echo $this-Form-input('postalcode');
 echo $this-Form-input('subscription_package');
 echo $this-Form-input('status');
 echo $this-Form-input('no_emails');
 echo $this-Form-input('no_partners');
 echo $this-Form-input('coupon_id');
 echo $this-Form-input('language');
 ?
 /fieldset
 ?= $this-Form-button(__('Submit')); ?
 ?= $this-Form-end(); ?
 /div
 div class=actions
 h3?= __('Actions'); ?/h3
 ul
 li?= $this-Html-link(__('List Vendors'), ['action' = 
 'index']); ?/li
 li?= $this-Html-link(__('List Coupons'), ['controller' = 
 'Coupons', 'action' = 'index']); ? /li
 li?= $this-Html-link(__('New Coupon'), ['controller' = 
 'Coupons', 'action' = 'add']); ? /li
 li?= $this-Html-link(__('List Partners'), ['controller' = 
 'Partners', 'action' = 'index']); ? /li
 li?= $this-Html-link(__('New Partner'), ['controller' = 
 'Partners', 'action' = 'add']); ? /li
 li?= $this-Html-link(__('List VendorManagers'), ['controller' 
 = 'VendorManagers', 'action' = 'index']); ? /li
 li?= $this-Html-link(__('New Vendor Manager'), ['controller' 
 = 'VendorManagers', 'action' = 'add']); ? /li
 /ul
 /div

 ==

 The above code is to create separate forms for each table. My requirement 
 is to make a single signup form for all the 3 tables.

 Apologize to be a continuing burdan...

 Regards,
 Jipson


 On Tuesday, 5 August 2014 10:11:36 UTC+1, José Lorenzo wrote:

 I find hard to believe that the form you showed above was generated by 
 bake, but I can definitely look if there is any errors in the bake tool. 
 The reason I say that is that we are not using the 'UppercaseThing.field' 
 notation anymore, we use lowercase properties.
 For example if Articles belongsTo Authors the form would look like:

  ?php echo $this-Form-input('title') ?
  ?php echo $this-Form-input('author.name') ?
  ?php echo $this-Form-input('author.email') ?

 On Tuesday, August 5, 2014 10:48:56 AM UTC+2, Jipson Thomas wrote:

 Hi Jose,
 Yes , I did the controller, model and view creation through the bake 
 console. But it is not helping me to save data from single form to multiple 
 tables. In my case the vendor signup form is having the input  fields to 
 vendor table, vendor manager table and a user table. Would you please help 
 me to find a solution on this?

 Regards,
 Jipson

 On Monday, 4 August 2014 18:26:48 UTC+1, José Lorenzo wrote:

 I would recommend that you use the bake console tool to create the 
 initial controller code and forms, that way I'm sure you will learn and 
 understand how forms should be structured.

 On Monday, August 4, 2014 5:46:29 PM UTC+2, Jipson Thomas wrote:

 Hi,
 When I change the controller code as follows, It saves in vendor table 
 only and return a true value.

 $vendors = TableRegistry::get('Vendors');
 
 if ($this-request-is('post')) {
 $vendor = new Vendor($this-request-data['Vendor']);
 $vendor-VendorManagers = [
 new 
 VendorManager($this-request-data['VendorManager']),
 ];
 $vendor-Users = [
 new User($this-request-data['User']),
 ];
 //print_r($vendor);
 if ($vendors-save($vendor)) {
 $this-Flash-success(__('The vendor has been saved'));
 return $this-redirect(['action' = 'index']);
 }
 $this-Flash-error(__('Unable to add the vendor'));
 }
 $this-set('vendor', $vendor);
 $this-set('subscription_package', $id);
 $this-set('subscription_type', $payoption);

 On Monday, 4 August 2014 16:17:10 UTC+1, Jipson Thomas wrote:

 The save method is returning a false only not any error messages.

 On Monday, 4 August 2014 14:43:20 UTC+1, Jipson Thomas wrote:

 Hi All,
 Would you please give me some details or samples of saving data from 
 a single form to the 

Re: Saving data to Has Many relationship table from single form in CakePHP 3

2014-08-05 Thread Jipson Thomas
Thank you Jose. Now I am doing in that way. I will update you the result.
Regards,
Jipson

On Tuesday, 5 August 2014 12:33:48 UTC+1, José Lorenzo wrote:

 Do as I told you in my previous message: input('related_propery.field')

 On Tuesday, August 5, 2014 11:19:29 AM UTC+2, Jipson Thomas wrote:

 Hi Jose,
 Sorry. What I said in my last thread that I re created my models ,views 
 and controllers through bake (The code I pasted in an older thread was not 
 from bake command.). The form created through bake doesn't include the user 
 table inputs. I will paste the code of form generated through bake below.
 ===

 div class=vendors form
 ?= $this-Form-create($vendor); ?
 fieldset
 legend?= __('Add Vendor'); ?/legend
 ?php
 echo $this-Form-input('company_name');
 echo $this-Form-input('logo_url');
 echo $this-Form-input('email_domain');
 echo $this-Form-input('phone');
 echo $this-Form-input('fax');
 echo $this-Form-input('website');
 echo $this-Form-input('address');
 echo $this-Form-input('country');
 echo $this-Form-input('city');
 echo $this-Form-input('state');
 echo $this-Form-input('postalcode');
 echo $this-Form-input('subscription_package');
 echo $this-Form-input('status');
 echo $this-Form-input('no_emails');
 echo $this-Form-input('no_partners');
 echo $this-Form-input('coupon_id');
 echo $this-Form-input('language');
 ?
 /fieldset
 ?= $this-Form-button(__('Submit')); ?
 ?= $this-Form-end(); ?
 /div
 div class=actions
 h3?= __('Actions'); ?/h3
 ul
 li?= $this-Html-link(__('List Vendors'), ['action' = 
 'index']); ?/li
 li?= $this-Html-link(__('List Coupons'), ['controller' = 
 'Coupons', 'action' = 'index']); ? /li
 li?= $this-Html-link(__('New Coupon'), ['controller' = 
 'Coupons', 'action' = 'add']); ? /li
 li?= $this-Html-link(__('List Partners'), ['controller' = 
 'Partners', 'action' = 'index']); ? /li
 li?= $this-Html-link(__('New Partner'), ['controller' = 
 'Partners', 'action' = 'add']); ? /li
 li?= $this-Html-link(__('List VendorManagers'), 
 ['controller' = 'VendorManagers', 'action' = 'index']); ? /li
 li?= $this-Html-link(__('New Vendor Manager'), ['controller' 
 = 'VendorManagers', 'action' = 'add']); ? /li
 /ul
 /div

 ==

 The above code is to create separate forms for each table. My requirement 
 is to make a single signup form for all the 3 tables.

 Apologize to be a continuing burdan...

 Regards,
 Jipson


 On Tuesday, 5 August 2014 10:11:36 UTC+1, José Lorenzo wrote:

 I find hard to believe that the form you showed above was generated by 
 bake, but I can definitely look if there is any errors in the bake tool. 
 The reason I say that is that we are not using the 'UppercaseThing.field' 
 notation anymore, we use lowercase properties.
 For example if Articles belongsTo Authors the form would look like:

  ?php echo $this-Form-input('title') ?
  ?php echo $this-Form-input('author.name') ?
  ?php echo $this-Form-input('author.email') ?

 On Tuesday, August 5, 2014 10:48:56 AM UTC+2, Jipson Thomas wrote:

 Hi Jose,
 Yes , I did the controller, model and view creation through the bake 
 console. But it is not helping me to save data from single form to 
 multiple 
 tables. In my case the vendor signup form is having the input  fields to 
 vendor table, vendor manager table and a user table. Would you please help 
 me to find a solution on this?

 Regards,
 Jipson

 On Monday, 4 August 2014 18:26:48 UTC+1, José Lorenzo wrote:

 I would recommend that you use the bake console tool to create the 
 initial controller code and forms, that way I'm sure you will learn and 
 understand how forms should be structured.

 On Monday, August 4, 2014 5:46:29 PM UTC+2, Jipson Thomas wrote:

 Hi,
 When I change the controller code as follows, It saves in vendor 
 table only and return a true value.

 $vendors = TableRegistry::get('Vendors');
 
 if ($this-request-is('post')) {
 $vendor = new Vendor($this-request-data['Vendor']);
 $vendor-VendorManagers = [
 new 
 VendorManager($this-request-data['VendorManager']),
 ];
 $vendor-Users = [
 new User($this-request-data['User']),
 ];
 //print_r($vendor);
 if ($vendors-save($vendor)) {
 $this-Flash-success(__('The vendor has been 
 saved'));
 return $this-redirect(['action' = 'index']);
 }
 $this-Flash-error(__('Unable to add the vendor'));
 }
 $this-set('vendor', $vendor);
 $this-set('subscription_package', $id);
 $this-set('subscription_type', $payoption);

 On Monday, 4 August 2014 16:17:10 UTC+1, Jipson Thomas wrote:

 The save method is returning a false only not any error messages.

 On 

Saving data to Has Many relationship table from single form in CakePHP 3

2014-08-04 Thread Jipson Thomas
Hi All,
Would you please give me some details or samples of saving data from a 
single form to the tables main and has many relationships. I tries with the 
normal way by adding a modelname.fieldname on form and the sual newentity 
of main table but it through false on save(); Please help me to fix this

Regards,
Jipson

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.


Re: Saving data to Has Many relationship table from single form in CakePHP 3

2014-08-04 Thread José Lorenzo
Have you tried following the instructions in the book? What is failing?

On Monday, August 4, 2014 3:43:20 PM UTC+2, Jipson Thomas wrote:

 Hi All,
 Would you please give me some details or samples of saving data from a 
 single form to the tables main and has many relationships. I tries with the 
 normal way by adding a modelname.fieldname on form and the sual newentity 
 of main table but it through false on save(); Please help me to fix this

 Regards,
 Jipson


-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.


Re: Saving data to Has Many relationship table from single form in CakePHP 3

2014-08-04 Thread Jipson Thomas
Hi Jose Lorenzo,
Thank you. I am following the book on following url to do this.
http://book.cakephp.org/3.0/en/orm/table-objects.html
Something is blocking to save data.
My Table structure is as follows.
===
A Vendor Table
A Vendor manager table with vendor_id and user_id fields
A user table.

*My Vendorstable.php file*
=
?php
// src/Model/Table/VendorsTable.php
namespace App\Model\Table;

use Cake\ORM\Table;
use Cake\Validation\Validator;
class VendorsTable extends Table {


public function validationDefault(Validator $validator) {
$validator
-notEmpty('company_name','Company Name is required')
-notEmpty('postalcode','Zip /Postcode is required')
-notEmpty('subscription_package','Couldn\'t find a valid 
package')
-notEmpty('country','Country is required');

return $validator;
}
public function initialize(array $config) {
$this-addBehavior('Timestamp', [
'events' = [
'Model.beforeSave' = [
'created_on' = 'new',
'modified_on' = 'always',
]

]
]);
$this-belongsTo('SubscriptionPackages', [
'foreignKey' = 'subscription_package'
]);
 $this-hasMany('VendorManagers');
 $this-hasMany('Users', [ 'through' = 'VendorManagers']);

}
}
*VendorManagersTable.php*
==
?php
// src/Model/Table/VendorManagersTable.php
namespace App\Model\Table;

use Cake\ORM\Table;
use Cake\Validation\Validator;
class VendorManagersTable extends Table {

public function initialize(array $config) {
$this-addBehavior('Timestamp', [
'events' = [
'Model.beforeSave' = [
'created_on' = 'new',
'modified_on' = 'always',
]

]
]);
$this-belongsTo('Vendors');
$this-belongsTo('Users');


}
}
*UsersTable.php*
===
?php
// src/Model/Table/UsersTable.php
namespace App\Model\Table;

use Cake\ORM\Table;
use Cake\Validation\Validator;
class UsersTable extends Table {


public function validationDefault(Validator $validator) {
$validator
 -add('username', 'validFormat', [
'rule' = 'email',
'message' = 'Username must be valid e-mail'
])
-add('username', [
'unique' = ['rule' = 'validateUnique', 'provider' = 
'table']
])
-add('email', 'validFormat', [
'rule' = 'email',
'message' = 'E-mail must be valid'
])
-add('email', [
'unique' = ['rule' = 'validateUnique', 'provider' = 
'table']
])
-add('password', [
'minLength' = [
'rule' = ['minLength', 6],
'last' = true,
'message' = 'Password must have minimum %d characters.'
],
'maxLength' = [
'rule' = ['maxLength', 15],
'message' = 'Password can have maximum %d characters'
]
])
-notEmpty('role','A valid role is required');

return $validator;
}
public function initialize(array $config) {
$this-addBehavior('Timestamp', [
'events' = [
'Model.beforeSave' = [
'created_on' = 'new',
'modified_on' = 'always',
]

]
]);
$this-hasMany('VendorManagers');
}
}

*Controller Function to save form*
==
public function buypackage($id,$payoption='monthly'){
 

$vendors = TableRegistry::get('Vendors');
$entity = $vendors-newEntity($this-request-data(), [
'associated' = ['VendorManagers' = ['associated' = ['Users']]
]
]);
if ($this-request-is('post')) {
if ($this-Vendors-save($entity)) {
 $this-Flash-success(__('The vendor has been saved'));
 return $this-redirect(['action' = 'index']);
}
$this-Flash-error(__('Unable to add the vendor'));
}
$this-set('vendor', $vendors);
$this-set('subscription_package', $id);
$this-set('subscription_type', $payoption);
}

*Form - buypackage.ctp*
===

div class=vendors form
?php echo $this-Flash-render('auth') ?
?php echo $this-Form-create($vendor) ?
fieldset
legend?php echo __('Company Details') ?/legend
?php echo $this-Form-input('Vendor.name',['label'='Vendor 
Name']) ?
?php echo $this-Form-input('Vendor.logo', ['type' = 'file']);?
?php echo $this-Form-input('Vendor.fax') ?
?php echo 

Re: Saving data to Has Many relationship table from single form in CakePHP 3

2014-08-04 Thread Jipson Thomas
The save method is returning a false only not any error messages.

On Monday, 4 August 2014 14:43:20 UTC+1, Jipson Thomas wrote:

 Hi All,
 Would you please give me some details or samples of saving data from a 
 single form to the tables main and has many relationships. I tries with the 
 normal way by adding a modelname.fieldname on form and the sual newentity 
 of main table but it through false on save(); Please help me to fix this

 Regards,
 Jipson


-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.


Re: Saving data to Has Many relationship table from single form in CakePHP 3

2014-08-04 Thread Jipson Thomas
Hi,
When I change the controller code as follows, It saves in vendor table only 
and return a true value.

$vendors = TableRegistry::get('Vendors');

if ($this-request-is('post')) {
$vendor = new Vendor($this-request-data['Vendor']);
$vendor-VendorManagers = [
new VendorManager($this-request-data['VendorManager']),
];
$vendor-Users = [
new User($this-request-data['User']),
];
//print_r($vendor);
if ($vendors-save($vendor)) {
$this-Flash-success(__('The vendor has been saved'));
return $this-redirect(['action' = 'index']);
}
$this-Flash-error(__('Unable to add the vendor'));
}
$this-set('vendor', $vendor);
$this-set('subscription_package', $id);
$this-set('subscription_type', $payoption);

On Monday, 4 August 2014 16:17:10 UTC+1, Jipson Thomas wrote:

 The save method is returning a false only not any error messages.

 On Monday, 4 August 2014 14:43:20 UTC+1, Jipson Thomas wrote:

 Hi All,
 Would you please give me some details or samples of saving data from a 
 single form to the tables main and has many relationships. I tries with the 
 normal way by adding a modelname.fieldname on form and the sual newentity 
 of main table but it through false on save(); Please help me to fix this

 Regards,
 Jipson



-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.


Re: Saving data to Has Many relationship table from single form in CakePHP 3

2014-08-04 Thread José Lorenzo
I would recommend that you use the bake console tool to create the initial 
controller code and forms, that way I'm sure you will learn and understand 
how forms should be structured.

On Monday, August 4, 2014 5:46:29 PM UTC+2, Jipson Thomas wrote:

 Hi,
 When I change the controller code as follows, It saves in vendor table 
 only and return a true value.

 $vendors = TableRegistry::get('Vendors');
 
 if ($this-request-is('post')) {
 $vendor = new Vendor($this-request-data['Vendor']);
 $vendor-VendorManagers = [
 new VendorManager($this-request-data['VendorManager']),
 ];
 $vendor-Users = [
 new User($this-request-data['User']),
 ];
 //print_r($vendor);
 if ($vendors-save($vendor)) {
 $this-Flash-success(__('The vendor has been saved'));
 return $this-redirect(['action' = 'index']);
 }
 $this-Flash-error(__('Unable to add the vendor'));
 }
 $this-set('vendor', $vendor);
 $this-set('subscription_package', $id);
 $this-set('subscription_type', $payoption);

 On Monday, 4 August 2014 16:17:10 UTC+1, Jipson Thomas wrote:

 The save method is returning a false only not any error messages.

 On Monday, 4 August 2014 14:43:20 UTC+1, Jipson Thomas wrote:

 Hi All,
 Would you please give me some details or samples of saving data from a 
 single form to the tables main and has many relationships. I tries with the 
 normal way by adding a modelname.fieldname on form and the sual newentity 
 of main table but it through false on save(); Please help me to fix this

 Regards,
 Jipson



-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.