In the recipe Adding catch-all routes for profile pages, we created routes so that profile pages can be accessed, specifying only the username in the URL.
In this recipe, we will learn how to implement a custom validation method so that these usernames do not conflict with other custom routes.
We need some sample data to work with, and we need a catch-all route. Follow the entire recipe Adding catch-all routes for profile pages.
We also need the sign-up page, where new profile records are created. Edit your app/controller/profiles_controller.php
file and place the following method inside the ProfilesController
class definition:
public function add() { if (!empty($this->data)) { $this->Profile->create($this->data); if ($this->Profile->save()) { $this->Session->setFlash('Profile created'); $this->redirect(array( 'action'=>'view', 'userName' => $this->data['Profile']['username'] )); } else { $this->Session...