php


Creating multiple models from one model in CakePHP


I have a users and a clients table.
They are linked as follows:
-- -----------------------------------------------------
-- Table `users`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `users` (
`id` INT(11) NOT NULL AUTO_INCREMENT,
`email` VARCHAR(45) NOT NULL,
`password` VARCHAR(255) NOT NULL,
`usertype` CHAR(2) NOT NULL,
`created` DATETIME NOT NULL,
`modified` DATETIME NULL DEFAULT NULL,
`firstname` VARCHAR(45) NOT NULL,
`lastname` VARCHAR(45) NOT NULL,
`phonenumber` VARCHAR(45) NOT NULL,
`suburb` VARCHAR(45) NOT NULL,
`state` VARCHAR(10) NOT NULL,
`businessname` VARCHAR(45) NULL DEFAULT NULL,
`image` BLOB NULL DEFAULT NULL,
`valid` INT NOT NULL,
PRIMARY KEY (`id`),
UNIQUE INDEX `email_UNIQUE` (`email` ASC))
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8;
-- -----------------------------------------------------
-- Table `clients`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `clients` (
`id` INT NOT NULL AUTO_INCREMENT,
`user_id` INT NOT NULL,
PRIMARY KEY (`id`),
INDEX `CLIENTS_FK_idx` (`user_id` ASC),
CONSTRAINT `CLIENTS_FK`
FOREIGN KEY (`user_id`)
REFERENCES `users` (`id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
I have baked these two tables and I have created a users registration page. Upon form submission I want the database to create both a user and a client object.
Here is my UsersController method form CakePHP:
public function clientregistration()
{
//Register a new client. Client enters all details and the system sets usertype=CL
$user = $this->Users->newEntity();
if ($this->request->is('post')) {
$user = $this->Users->patchEntity($user, $this->request->getData());
$user->usertype = 'CL';
$user->valid = 1;
if ($this->Users->save($user) && $this->Coaches->($coach)) {
$this->Flash->success(__('You have successfully registered.'));
return $this->redirect(['action' => 'login']);
}
$this->Flash->error(__('Registration failure. Please, try again.'));
}
$this->set(compact('user'));
$this->set('_serialize', ['user']);
I want the code to automatically pre-fill all data in the clients table as well.
How do I do this?

Related Links

Facebook Graph API - Get Page Notifications
How to use foreach while only defining the key
Xampp Access Denied phpmyadmin not connecting to MySQL
How to extract URL tag in Json using php
How to make the table responsive when exporting from Mysql via PHP with EZPDF
Parse error: syntax error, unexpected '}' [duplicate]
Running Where IN by imploding an array, but output is a string and does not run in MySQL as expected
Errors in Laravel Project
Updating MySQL data via PHP. Says successful but isn't [closed]
Advice on reducing server overhead of rapidly called PHP script from AJAX
Partition array into multiple arrays, by hours
Model relation not being set in Laravel. Why?
How to make a dynamic price view for checkout
So how to print condition specific result on view in case the second block has nested db queries in Codeigniter?
Persist object in PostPersist, PostUpdate events
Enable hebrew on mysql database [wamp]

Categories

HOME
opengl
artificial-intelligence
class
lambda
tomcat
blast
eclipse-plugin
d3.js
softlayer
writefile
add-on
hdfs
ant
adobe
jersey-2.0
twitter-fabric
impala
angular-meteor
bellman-ford
hystrix
yeoman-generator-angular
angular4
dhcp
jqxgrid
scala-ide
nose
multiple-tables
raml
pe
firemonkey-style
react-dnd
prompt
acrobat
laravel-4.2
ninject
cloveretl
buildforge
nppexec
cups
cartopy
unification
rdp
spring-restcontroller
oauth2
newtons-method
pyttsx
raytracing
morphline
reverse-dns
icecast
subforms
pen
1010
msxml
front-camera
wildfly-9
thread-exceptions
libharu
urbit
django-redis
helm
embeddedwebserver
angular-amd
prism-4
nssortdescriptor
htmltidy
loginview
rpg
lsa
saga
illuminate-container
infinite
sql-view
chartfx
jquery-lazyload
oembed
red-system
semantic-merge
pageheap
kobold2d
sigar
fbml
mmc3
database-deadlocks
kernel32
asp.net-mvc-views
anonymous-types
mongrel2
jdownloader
iphone-sdk-4.3
spring-modules
fxruby
.net-client-profile
objectinstantiation
bindable-linq

Resources

Encrypt Message



code
soft
python
ios
c
html
jquery
cloud
mobile