Reputation: 2415
I've just started reading up on CakePHP and everything is going pretty good so far, though I have a query on the best way to do the following:
I have a "User" model and a "UsersController" controller.
I currently have a "home" page which is controlled by the home_controller.php (obviously). The home page contains a registration for for a user.
The Question
When the form is posted from the home page, I need to access the User model (from the home controller).
What is the best practice for this task?
Upvotes: 0
Views: 313
Reputation: 21743
you can easily share one model across many controllers
var $uses = array('ModelName');
I do that with User Model and
for example. they all share the User Model.
Upvotes: 1
Reputation: 5481
I currently have a "home" page which is controlled by the home_controller.php (obviously)
What other methods do you have in home_controller, other than index? And in Cake convention, the controller is plural, so: users, categories... Most likely, you are not aware of pages_controller and routing in Cake.
Anyway, yes, you can make a post to any controller (or even to another domain) from any page, just like any regular HTML page. echo $this->Form->create('User', array('controller'=>'users','action' => 'register'));
You can read more here: http://book.cakephp.org/view/1384/Creating-Forms
Upvotes: 0
Reputation: 740
If I understand the situation correctly, I would post the form to some function in users controller. Then this function would save the data, or log in, or whatever. Finally make redirect back to home for example.
Upvotes: 1