Leave a Reply

If you need to post a piece of code use {code type=php}...{/code}.
Allowed types are "php", "mysql", "html", "js", "css".

Please do not escape your post (leave all ", <, > and & as they are!). If you have encoded characters and need to reverse ("decode") it, you can do that here!

  1. Adam

    October 8, 2015 at 17:02

    Your approach to edit own profile is an awesome hack. Thanks!

    Maybe for version difference reasons your code didnt work. Am on CakePHP 3.0. My solution:

    &gt; Controller:

    public function editme() {
            $uid = $this->request->session()->read('');
            $user = $this->Users->get($uid, []);
            if ($this->request->is(['patch', 'post', 'put'])) {
                $user = $this->Users->patchEntity($user, $this->request->data);
                if ($this->Users->save($user)) {
                    $this->Flash->success(__('Your account changes have been saved.'));
                } else {
                    $this->Flash->error(__('Something went wrong and your changes were not saved. Try again.'));
            $this->set('_serialize', ['user']);

    View template:

    Form->create($user); ?>
                echo $this->Form->input('last_name');
                echo $this->Form->input('email');
                echo $this->Form->input('password');
                echo $this->Form->hidden('active', [
                  'default' => '1'


  2. JM

    November 12, 2015 at 07:16

    im currently working on my cakephp app i have database named time and is has to table users and accounts users have EployeeId, Password data fields and accounts has also EmployeeId , Password etc.. now what i want to happen is every time that i will add data to users table it will authenticate if that data to save is present in the accounts table if not it will flash error else it will save how can i do this in cakephp ?? here is may

    add.ctp code

    public function add()
    $user = $this-&gt;Users-&gt;newEntity();
    if ($this-&gt;request-&gt;is(‘post’)) {
    $user = $this-&gt;Users-&gt;patchEntity($user, $this-&gt;request-&gt;data);
    if ($this-&gt;Users-&gt;save($user)) {
    $this-&gt;Flash-&gt;success((‘Logs has been saved.’));
    return $this-&gt;redirect([‘action’ =&gt; ‘index’]);
    } else {
    (‘The logs could not be saved. Please, try again.’));
    $this-&gt;set(‘_serialize’, [‘user’]);