How to create a username in route

behavior

#1

Please how can i be able to create a username in my route. example domain.com/username


#2

Do you not need a password? Normally a form is used to create a new user with a password and is posted via a route to a controller, and the password is bcrypted. Study the manual on https://book.cakephp.org/3.0/en/controllers/components/authentication.html


#3

Ok, what I really need is a username route like Facebook.com/username


#4

You can try this but you have to handle it with care because if this route will conflict with others you will get an error page.
You just have to build a method which will take a parameter the username. e.g. you can build a profile method in users controller and the route will be like.

$routes->connect(’/:username’,[‘controller’ => ‘Users’, ‘action’ => ‘profile’],[‘pass’ => [‘username’]]);


#5

What i did before now is this
Router::connect(’/-:username’,
array(
‘controller’=>‘users’,
‘action’=>‘view’
),
array(
‘pass’ => array(‘username’),
‘username’ => ‘\b(?:(?!admin|items|images)\w)+\b’
)
);
But i want to remove this connect(’/-: , the dash, each time i remove it, i will have an error.
I want it to be like this connect(’/:username


#6

Working fine for me without “-”.


#7

ok Thanks. I will try it again and get back to you.