CakePHP - Passing Data Between Models
This is my last hope...I have been trying to figure this out all day and I am out of gas. I have an appointment application that an operator in开发者_Python百科puts phone, business, name, and call result (Customers Controller). The call result then goes to the Appointments controller. Lets say the operator setups up an appointment, I then now need to setup an appointment for the customer I just entered. But when I try and setup a new appointment for the new customer I just get sent back to the Appointments index view instead of the form. What am I doing wrong? I need some other eyes on this. My development team has all been laid off and I am the last one left, so I don't have anyone to bounce ideas and code off. Please help. I don't even know if I am asking the right question at this point.
function step1() {
$this->set('title_for_layout','Make a New Call');
if (!empty($this->data)) {
$this->Customer->create();
$this->data['Customer']['user_id'] = $this->Auth->user('id');
if ($this->Customer->save($this->data)) {
$this->Session->setFlash(__('The customer has been saved', true));
//??? WHAT DO I PUT HERE TO GO TO THE APPOINTMENTS CONTROLLER WITH THIS CUSTOMER DATA
} else {
$this->Session->setFlash(__('The customer could not be saved. Please, try again.', true));
}
}
}
Try this after saving the data
if ($this->Customer->save($this->data)) {
$this->Session->setFlash(__('The customer has been saved', true));
$id = $this->ModelName->getInsertID();
$this->redirect("customers/index/$id");
Now you've the id and fetch the data over there. Or if you want to pass the entire array to that function then try this link simple cakephp problem
Where did you get $customer ? it isn't initialize
so you can save data in session but it isn't good idea
$this->Session->write('data',$this->data);
also uoy can transfer customer id to another controller like this
$this->redirect("/appointments /step2/{$id}/");
// this is in appointments controller
function step2($id = null){
if($id){
$this->loadModel('Customer');
$customer = $this->Customer->findById($id);
}
}
something like this, hope it helps
精彩评论