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

MySQL query working in PHPMyAdmin but not working in PHP
Setting up CreateBundle - Document is not managed and has no id
Get Response while sending mail through sendgrid using PHP
Images are cropped in MasterSlider jquery plugin
jquery to hide column from exporting to excel
php mysql retrieving single value from database
Upload image to host
using php to move a file
Post data that contains paths with ../../ gives empty $_POST array
Where does 'font-size: 13.333333969116211px' come from?
download file from another codeigniter website through our download function
Error when INSERT array into table [duplicate]
regexp assistance (already provided) [duplicate]
Trying to get property of non-object when its clearly a property on an object
How to display array -1 in foreach
Framework for storing settings in a database (PHP and MySQL) [closed]

Categories

HOME
mod-rewrite
matrix
xcode
apple-push-notifications
cucumber
barcode-scanner
enums
nsview
cryptography
implicit-conversion
cisco
getopenfilename
alljoyn
tiff
pm2
texas-instruments
office-ui-fabric
renderscript
cpu-usage
error-logging
coreldraw
webviewclient
spreadsheetgear
sap-lumira
jackrabbit-oak
react-bootstrap-table
javax.persistence
social-networking
docx4j
fotorama
nest
devtools
directfb
aurelia-http-client
assemblies
grails-spring-security
web-inspector
apache-toree
destroy
swift2.3
image-registration
sharpdx
exc-bad-access
lvalue
rcharts
zend-server
business-rules
sidewaffle
openerp-6
perl-data-structures
finder
xcode6.4
jsonix
dcount
callouts
conan
maven-release-plugin
groovyfx
currency-exchange-rates
diawi
stack-smash
opencyc
vdm-sl
domino-designer-eclipse
rebar
wicket-1.5
igor
loginview
angular-ui-select
rpg
xmi
ctp
vlab
discovery
apache-shindig
acitree
ember-table
jacob
bcdedit
xs
donut-chart
coordinate
server-variables
nsrangeexception
winsxs
startupscript
kohana-auth
bass
odac
asdoc
html-components
database-cloning
iphone-sdk-3.1.3
prism-2
bindable-linq

Resources

Encrypt Message



code
soft
python
ios
c
html
jquery
cloud
mobile