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

How to check the exception thrown correctly by PHPUnit?
How to encrypt the $_GET data in php?
jquery mobile lost css with ajax post
if div with id has certain text remove other div
PHP inside PHP Syntax and Logic
How to send sms using php script from ftp server
Regex phone validation
MySql, PHP display Picture on HTml
Updating a page element in a php script
jQuery: Ajax before submitting form
subdomain to url redirect with mod_rewrite and htaccess?
associate cakephp model to non-cakephp database table
Adding Content-type to Pear Mail
Form Evaluation With PHP
Loading an array of arrays from mysql
Parsing text in php

Categories

HOME
visual-studio
android-studio
memory
azure-functions
eclipse-plugin
out-of-memory
ontology
drag-and-drop
responsive-design
bootstrap-switch
android-externalstorage
powermock
squid
rest-assured
gmp
tfsbuild
parceler
spring-shell
weex
sqlplus
qa
jpa-2.1
tortoisemerge
clipboard
ibm-connections
envoy
intune
memory-fences
series
cucumber-junit
osx-lion
ms-media-foundation
subclassing
ftp-server
ms-solver-foundation
twilio-php
identify
mv
flowchart
system-on-chip
oauth2-playground
ejml
julius-speech
doctrine-extensions
music21
adblock
node-apn
exc-bad-access
winmerge
sesame
kendo-treeview
oid
cocoa-bindings
openquery
mathml
dpkg
fragmentstatepageradapter
codecharge
jemdoc
textblock
okta-api
android-expansion-files
json-spirit
variable-length-array
ibm-was
openshift-cartridge
nastran
gitlab-omnibus
embeddedwebserver
kotlin-android-extensions
tidyr
mojo
encryption-symmetric
producer
inputbox
thruway
bittorrent-sync
property-injection
mod-perl
discovery
jacob
sunstudio
blobstorage
axacropdf
asp.net-mvc-3-areas
examine
linkbutton
sfinae
memory-pool
datacontracts
winsxs
rtd
upshot
webresponse
channelfactory
formal-semantics
raw-data
tacit-programming
database-cloning

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App