I’m using cakephp 2.9.1
my app have a users and signup
when i want to view any user profile i found the link : xx.com/users/view/ [id]
and the [id] reefer to the user id in the database
i created another column in the db so whenever some one signup will choose unique username
i want to show the username in the link to the profile
to be xx.com/users/view/[username]
i searched a lot and did not find the line that directs to view/id
can you explain more please ?
what do you mean by templates ? which files in which directory ?
i did check /Users/view.ctp
and did not find anything related to the url
public function view($username = null)
{
// find user by user name
}
// in template
$this->Html->link($username, ['controller' => 'Users', 'action' => 'view', $username]);
the final generated html file is concetaned together from a few (or a lot of) different template files.
By default all controllers renders /src/Template/Layout/default.ctp
In this file you have a <?= $this->fetch('content') ?> line what actually calls the corresponding template file.
By default the url /users/view/XX will be handled by /src/Controller/UsersController.php file’s view method.
If you baked your controller this method requires to pass a user id, and it will find the appropiate user from the database and make the result available for the view (template). If you want to use username instead of id, you should change this method a little bit.
When the controller finished its work it will call /src/Template/Users/view.ctp to display the user.
Your layout and your template files can include other elements (from /src/Template/Element) and these will be also included in the generated HTML document.
so i create public function view($username = null)
in my Usercontroller
and where exactly to put the line for template … under echo $this->fetch(‘content’); ?
Yes i’m on that same file but where exactly to put this code $this->Html->link(h($username), ['controller' => 'Users', 'action' => 'view', $username]);