I want my url like this format http://localhost/blog/users/username instead of this http://localhost/blog/users/view/6
I have this code in Users view index.ctp
<?php foreach ($users as $user): ?>
<?= $this->Html->link(__('View Profile'), ['action' => 'view', $user['user']['slug']]) ?>
<?php endforeach; ?>
routes.php
<?php
$routes->connect('/user/*', array('controller' => 'users', 'action' => 'view'));
?>
//public function view($id = null)
public function view($username)
{
$users = $this->Users->get($username, [
'contain' => ['Subjects'] // i have relation
]);
$this->set('users', $users);
$this->set('_serialize', ['user']);
}
I tried this link but it not solved my problem
public function edit($id = null)
{
//$logged_user_id=$this->request->Session()->read('Auth.user.id');
$logged_user_id=$this->Auth->user('id');
if($logged_user_id==$id){
$user = $this->Users->get($id, [
'contain' => []
]);
if ($this->request->is(['patch', 'post', 'put'])) {
$user = $this->Users->patchEntity($user, $this->request->getData());
if ($this->Users->save($user)) {
$this->Flash->success(__('User profile successfuly updated.'));
return $this->redirect(['action' => 'index']);
} else {
$this->Flash->error(__('The user could not be saved. Please, try again.'));
}
}
$this->set(compact('user'));
$this->set('_serialize', ['user']);
} else {
$this->Flash->error(__('You are not allowed to do this.'));
return $this->redirect(['action' => 'index']);
}
}