Your idea is the what I believe is the correct solution. Instead of calling $this->User->Skills->find... You'd call $this->User- >$modelName->find
You'd need to do something with the view_skills and view_educations type functions. Assuming they are similar you could do $this->view ($slug, $modelName), otherwise perhaps move them into the model and call $this->User->$modelName->view($slug); Walther. On Apr 10, 5:34 pm, "Dave Maharaj :: WidePixels.com" <[email protected]> wrote: > I was hoping for some info on how to take 4 functions and make the into > 1.They all do the same thing except its a different model that they use. > They simply update a users options thru a select check box form, that's the > only thing being edited. Basically I took the edit view and broke it up into > 4 different Ajax edits and each has its own function but since they are all > the same except for the model call I was hoping someone could give me some > advice on creating 1 standard function. > > They all get called from the same page users/profile, the link in the view > is users/profile/[user slug]/update_eductions or users/profile/[user > slug]/update_skills. I am still very new with cake but was thinking if I > modified the link url used an additional variable based on the link action > to get users/profile/[user slug]/educations/update I could then use 1 > function called update and set the "educations" in the url to define what > model to update and pass that into the function. the update function would > be something like function update ($slug, $modelName) then in the old > function replace the model name with $modelName ? > > function update_eductions($slug = null) > { > $this->User->recursive = 1; > if ($this->RequestHandler->isAjax()) { > $user = $this->User->findBySlug($slug); > $id = $user['User']['id']; > $this->set('user', $this->User->read(null, $id)); > if (!empty($this->data)) { > if ($this->User->save($this->data)) { > $this->view_educations($slug); > } > } > $educations= $this->User->Educations->find('list', > array('fields' => 'name', 'order' => 'name ASC')); > $this->set(compact('educations')); > } > if (empty($this->data)) { > $this->data = $this->User->read(null, $id); > } > } > > or to update skills > > function update_skills($slug = null) > { > $this->User->recursive = 1; > if ($this->RequestHandler->isAjax()) { > $user = $this->User->findBySlug($slug); > $id = $user['User']['id']; > $this->set('user', $this->User->read(null, $id)); > if (!empty($this->data)) { > if ($this->User->save($this->data)) { > $this->view_skills($slug); > } > } > $skills= $this->User->Skills->find('list', array('fields' => > 'name', 'order' => 'name ASC')); > $this->set(compact('skills')); > } > if (empty($this->data)) { > $this->data = $this->User->read(null, $id); > } > } > > Ideas? Suggestions? > > Thanks, > > Dave --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~----------~----~----~----~------~----~------~--~---
