-2

when i register with new user its always put null value in database. also topic to visible/ hide to admin and user.Please Solve it here is code:

public function add() {
    if ($this->request->is('post')) {
        $this->User->create();
        $this->request->data['User']['password'] = AuthComponent::password($this->request->data['User']['password']);
        $this->request->data['User']['role'] === '1';
        if ($this->User->save($this->request->data)) {
            $this->Session->setFlash(__('The user has been saved.'));
            return $this->redirect(array('action' => 'index'));
        } else {
            $this->Session->setFlash(__('The user could not be saved. Please, try again.'));
        }
    }
}

1 Answers1

0

This does not set 'role' to 1.

$this->request->data['User']['role'] === '1';

You need this:

$this->request->data['User']['role'] = 1;

EDIT:

$this->Auth->user('role') should be equal to your admin role. I hope it is 1 in your coding.

<?php if($this->Auth->user('role') == 1  || $topic['Topic']['visible'] == 1): ?>
  /* Your Topic */
<?php endif; ?>
NaahsTea
  • 1
  • 2
  • thank you but i have one more problem i set a visibility. 1 for visible and 2 for hidden but admin also didnt see the topics also set conditions for admin to see visible { } – ZuBaIr KhAn BaLoCh Mar 15 '15 at 06:06