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

Combining 2 different queries into one
Installing composer in godaddy shared hosting [closed]
How to replace ?query with /query
How do i clone an ArrayIterator in PHP?
PHP SkipList put method always returns null
How to use scrypt in php shared hosting
{date} function help. Fetch record from mysql of specific dates
Pass everything as string in PHP mysql_stmt::bind_param() [duplicate]
How to add information to string
Private Key with PHP and “openssl_pkey_get_details() expects parameter 1 to be resource”
How to Verify Password Hashes [duplicate]
CRON job doesn't run when I set a specific time
file_get_contents doesn't work if there is a dot(.) in the folder in Windows platform
I can not get The file from HTML to Php while trying to Upload
PHP - How do I correctly use a “if(isset() && != NULL) || (isset() && != NULL)” statement?
Parse csv file that came from base64 on PHP

Categories

HOME
entity-framework
magento2
verification
apple-push-notifications
clearcase
workflow
qc
stacktrace.js
hdfs
ios-simulator
slider
malware
mathematical-optimization
visualforce
share
repair
capistrano
save
csrf
complexity-theory
mailgun
async-await
tomcat8
tfsbuild
sqlplus
sipp
backendless
pyopencl
vuforia
ratio
tracing
android-cardview
acrobat
laravel-4.2
python-2.x
reporting
listjs
payeezy
creation
polyml
transform
keyboard-layout
landscape
pdfnet
jade4j
django-crispy-forms
aurelia-http-client
iscroll
flowchart
utf
ipp-protocol
realstudio
ilrepack
sigsegv
sequence-diagram
exc-bad-access
email-injection
gawk
fuzzer
cdo.message
qtcpsocket
groovyfx
apache-pig-grunt
codecharge
rails-engines
jeditable
xcopy
persistent-object-store
currency-exchange-rates
management-studio-express
django-validation
ajax4jsf
cryptojs
linuxbrew
ora-04091
dnx50
enaml
apple
android-handler
relational-model
dbmigrate
erlog
quercus
findersync
tkx
google-hangouts
storing-data
xhprof
lmax
nosql-aggregation
mod-perl
libxml-js
msinfo32
wiktionary
memory-pool
kernel32
formal-semantics
android-2.1-eclair
mongrel
bucket
rtti
bindable-linq

Resources

Database Users
RDBMS discuss
Database Dev&Adm
javascript
java
csharp
php
android
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App