Monday, June 23, 2014

Re: what is request array to save multiple records in cakephp3 ?

I have two tables resumes and links.resumes has many link and I defined has many relationship in ResumeTableI. I did it like following.

In Model/Table/ResumesTable.php
<?php
namespace App\Model\Table;
use Cake\ORM\Table;
use Cake\Validation\Validator;
$validator = new Validator();

class ResumesTable extends Table {
    public function initialize(array $config) {
        $this->addBehavior('Timestamp');
        $this->belongsTo('Users', [
            'foreignKey' => 'user_id',
        ]);
        $this->hasMany('Links', ['className' => 'Links',]);
    }

In ResumesController.php

$resume = $this->Resumes->newEntity($this->request->data);
        if ($this->Resumes->save($resume)) {
              // return true;
        }

On Monday, 23 June 2014 13:54:37 UTC+5:30, dada123 wrote:
$this->Model['User']['name'] = 'test'];

$this->User->save($this->data);

This should be the exact process of saving .


On Mon, Jun 23, 2014 at 12:11 PM, Archana Goyal <archana...@gmail.com> wrote:
Hi,
I am building cakephp 3 application. I want to save associated multiple records.
my $this->request->data is
Array  (         [name] => archana
[phone] => 234234
  [links] => Array ( [0] => Array ( ['link'] => www.google.com ['user_id'] => 1 ) ) )

In my associate table data saved like

id | link | user_id | resume_id
1 | | | 1

and I want like this
id | link               | user_id | resume_id
1 | www.google.com | 1 | 1

--
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+u...@googlegroups.com.
To post to this group, send email to cake...@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.



--
Regards

--
Soumavo Chattaraj


--
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+unsubscribe@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.

No comments: