<naked.cake.baker@gmail.com> wrote:
> How should this be set up?
> User can register as a Buyer or Seller each with different criteria needed
> in the form so 2 forms.
> Would you make 2 registration methods in the User controller
> buyer_registration() and seller_registration(){} or a register in buyer
> controller and register in seller controller? Each is a "User".
I use entirely separate models for this sort of thing. There are
various ways to approach extending models with Cake. I prefer to
extend AppModel as normal and add User to the model's $belongsTo .
Example:
class Member extends AppModel
{
public $belongsTo = array(
'User' => array(
'className' => 'User',
'foreignKey' => 'user_id'
),
'Country',
'Region'
);
class User extends AppModel
{
public $hasOne = array(
'Member' => array(
'className' => 'Member',
'foreignKey' => 'user_id',
'dependent' => true
),
'Affiliate' => array(
'className' => 'Affiliate',
'foreignKey' => 'user_id',
'dependent' => true
),
...
The users table has model & foreign_key columns. Logging in:
$model_name = $this->Auth->user('model');
$this->User->{$model_name}->recursive = -1;
$model = $this->User->{$model_name}->read(null,
$this->Auth->user('foreign_key'));
$this->Session->write(
"Auth.User.${model_name}",
$model[$model_name]
);
Then redirect based on model.
You could have separate register actions in BuyersController &
SellersController, or a single one in UsersController that takes a
model name as a param. After ensuring the model exists, just do
something like:
$this->User->{$model}->set($this->data);
if ($this->User->{$model}->validates())
{
$this->data['User']['foreign_key'] = $this->User->{$model}->getInsertID();
...
--
Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.
To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php
No comments:
Post a Comment