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

php traits, collisions with other trait methods
OctoberCMS: How to change the view of uploaded files for “attachMany” relation type?
How do I rename and delete mysql column names without deleting rows or records?
How to get the max and min of a data from child table with mysql and php?
i just want to add my session values in array but it display only the last elememt here is my code
Create new folder from public and use as a admin side in laravel
Server hacked, apache2 log contains get with a bash command
I get this error: “array_push() expects parameter 1 to be array, string given” even when the value is of type array
Unset bootstrap alerts after display
Matching inputed data to MySQL stored data. Token based auth style
Wordpress Fatal error: require(): Failed opening required on line 97
PHP: issuing a cron job once every 24hrs from initial date
Override Model property or method in laravel using service provider
A non well formed numeric value encountered using maths functions in cakephp3
XDebug is pausing just once
Using PHP MSSQL PDO with Plesk

Categories

HOME
python-2.7
spring-data
entity-framework
couchdb
enums
hdfs
web2py
gentelella
tfs2015
flurry
video-streaming
phpstorm-2017.1
csrf
feature-extraction
fosuserbundle
boomi
dashdb
sharedpreferences
multi-upload
cellular-network
background-color
math.js
region
dotcms
mapnik
nsmutablearray
knights-tour
android-canvas
autoencoder
cups
wdk
subclassing
mv
gitolite
game-center
plane
newtons-method
distributed-caching
flipkart
morphline
jenkins-slave
music21
qvtkwidget
node-apn
mongodb-aggregation
popen
network-protocols
fitbit
ternary-operator
jsonix
system.web.optimization
always-on-top
fiber
meld
frame-grab
preferenceactivity
okta-api
seadragon
boost-proto
python-cffi
linuxbrew
opencyc
wso2ml
wlanapi
uitest
roxygen2
componentart
flow-js
web-api
scala-macros
deque
gflags
htmltidy
directorysearcher
microsoft-expression-web
lifetime
comctl32
smacss
qt5.4
hyperloglog
reference-counting
xulrunner
nosql-aggregation
profiles
lsa
colon
microformats
notin
mongo-jackson-mapper
session-0-isolation
struts2-json-plugin
word-frequency
thejit
struts2-s2hibernate
firebird1.5
flymake
netstream
android-2.1-eclair
multiple-users
icicles
self-tracking-entities
inversion
index.dat
watchpoint

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