Crazy Sarah
Crazy Sarah

Reputation: 69

probably the most basic cakephp question in the world

sorry for my lack of knowledge here but I'm new to cakephp and while I've written the most basic php before I've never tried to do anything anywhere near complicated, so I'm out of my depth but loving learning all about cake.

Basically my app will have users who will be able to create profiles pages. After clicking go on the homepage, they will see a screen with a form on it. The inputs will be username, email and password for the user model plus I want them to enter a film-name and a colour which will be part of profile model.

They then click to submit and stuff gets submitted to my users_controller 'register' action which saves the user to the database etc and if all goes well redirects them to a page where they will enter more details. The trouble is I need to get access to the film-name and colour they entered before and I'm not sure how I should be handling that.

Should I be trying to save their profile to the database at the same time as saving their user details? If so how do I do that since I'd be in the users_controller?

I know I could ask for the user and profile details on separate screens but I really want them to choose their film and colour on the same screen as choosing their username. Plus I don't want to have to make film-name and colour part of the user model

Upvotes: 2

Views: 136

Answers (1)

Jack Murdoch
Jack Murdoch

Reputation: 2894

A controller can access multiple models using $uses.

class UsersController extends AppController {
    var $uses = array('User', 'Profile');
    ...

These can then be accessed as normal.

$this->Profile->save($this->data["Profile"]);

You could then save the profile data at this point, and then forward to the profile editing page, allowing the user a chance to double check the details they've already entered, and enter any additional fields if applicable.

Upvotes: 2

Related Questions