hi all I’m trying to search a database for a username using cakephp, the username isnt the primary key in the database but it must be unique. here is the code I have for the search function but cake does not like it.
function index(){
$this->User->recursive = 0;
if ($this->data['users']['username']) {
$this->set('users',
$this->paginate('users', array('or' => array('users.username LIKE' => '%' . )));
else {
$this->set('users', $this->paginate());
}
}
}
the database contains a id(the primary key) and a username. The goal of this is to send a friend request. User searches the username and then if the username is there, the other user will receive their request in a relationship inbox and can select ‘yes’ or ‘no’.
the other thing is, if the username exists I want the data to be stored in a table called users_users – i realize i dont have any code for what to do once the search has happened. but I am pulling my hair out trying to figure this out as their doesnt seem to be many tutorials on the web for this.
Make sure your usernames are unique by validating it when they’re entered.
http://book.cakephp.org/2.0/en/models/data-validation.html
I’m not sure, but this users.username looks like you’re using the username as foreign key in the jointable!? Thats totally wrong.
Even if it would be then the notation is wrong and does not follow the CakePHP standards and won’t work. It should be User.username then.
I would suggest you to start over with the blog tutorial for CakePHP and read the book.