# How to create a username in route

**URL:** <https://discourse.cakephp.org/t/how-to-create-a-username-in-route/2369>\
**Category:** Uncategorized\
**Tags:** behavior\
**Created:** [April 6, 2017, 10:41am UTC](https://discourse.cakephp.org/t/how-to-create-a-username-in-route/2369 "2017-04-06T10:41:22Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![pejonic](https://avatars.discourse-cdn.com/v4/letter/p/bbce88/32.png) [@pejonic](https://discourse.cakephp.org/u/pejonic)\
**Post date:** [April 6, 2017, 10:41am UTC](https://discourse.cakephp.org/t/how-to-create-a-username-in-route/2369/1 "2017-04-06T10:41:22Z")

</div>

Please how can i be able to create a username in my route. example [domain.com/username](http://domain.com/username)

---

<div class="post-metadata">

**Author:** ![jimgwhit](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/jimgwhit/32/378_2.png) [@jimgwhit](https://discourse.cakephp.org/u/jimgwhit)\
**Post date:** [April 7, 2017, 2:19am UTC](https://discourse.cakephp.org/t/how-to-create-a-username-in-route/2369/2 "2017-04-07T02:19:39Z")

</div>

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](https://book.cakephp.org/3.0/en/controllers/components/authentication.html)

---

<div class="post-metadata">

**Author:** ![pejonic](https://avatars.discourse-cdn.com/v4/letter/p/bbce88/32.png) [@pejonic](https://discourse.cakephp.org/u/pejonic)\
**Post date:** [April 7, 2017, 3:45am UTC](https://discourse.cakephp.org/t/how-to-create-a-username-in-route/2369/3 "2017-04-07T03:45:25Z")

</div>

Ok, what I really need is a username route like [Facebook.com/username](http://Facebook.com/username)

---

<div class="post-metadata">

**Author:** ![aavrug](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/aavrug/32/178_2.png) [@aavrug](https://discourse.cakephp.org/u/aavrug)\
**Post date:** [April 7, 2017, 4:47am UTC](https://discourse.cakephp.org/t/how-to-create-a-username-in-route/2369/4 "2017-04-07T04:47:30Z")

</div>

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’]]);

---

<div class="post-metadata">

**Author:** ![pejonic](https://avatars.discourse-cdn.com/v4/letter/p/bbce88/32.png) [@pejonic](https://discourse.cakephp.org/u/pejonic)\
**Post date:** [April 7, 2017, 6:57am UTC](https://discourse.cakephp.org/t/how-to-create-a-username-in-route/2369/5 "2017-04-07T06:57:43Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![aavrug](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/aavrug/32/178_2.png) [@aavrug](https://discourse.cakephp.org/u/aavrug)\
**Post date:** [April 7, 2017, 7:04am UTC](https://discourse.cakephp.org/t/how-to-create-a-username-in-route/2369/6 "2017-04-07T07:04:25Z")

</div>

Working fine for me without “-”.

---

<div class="post-metadata">

**Author:** ![pejonic](https://avatars.discourse-cdn.com/v4/letter/p/bbce88/32.png) [@pejonic](https://discourse.cakephp.org/u/pejonic)\
**Post date:** [April 7, 2017, 7:16am UTC](https://discourse.cakephp.org/t/how-to-create-a-username-in-route/2369/7 "2017-04-07T07:16:15Z")

</div>

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