0

controller code:

    public function login()
    {
        $this->LoadModel('Users');

        pr($this->data);
    }

View code:

<?php echo
$this->Form->create('Post').
$this->Form->control('email').'<br>'.
$this->form->label('password').'<br>'.
$this->Form->password('password').'<br>'.
$this->Form->submit('log in').
$this->Form->end();
?>

I fail to understand that Data is submitted to controller but to read data from controller. I get that data saved with controller but to access data variable ie submit form data unable to read to controller.

1 Answers1

0

To get post data, use debug

debug($this->request->getData()); 

It's looking like you need all CRUD code.

So, you can create your user add.ctp file below

location : templates\Users\add.ctp

<?= $this->Form->create($user) ?>

<?php
   echo $this->Form->control('username');
   echo $this->Form->control('email');
   echo $this->Form->control('password');
?>

<?= $this->Form->button(__('Submit')) ?>
<?= $this->Form->end() ?>

Then users controller look like

 UsersController/add method look like 

 public function add()
    {
        $user = $this->Users->newEmptyEntity();
        if ($this->request->is('post')) {
            $user = $this->Users->patchEntity($user, $this->request->getData());
            if ($this->Users->save($user)) {
                $this->Flash->success(__('The user has been saved.'));

                return $this->redirect(['action' => 'index']);
            }
            $this->Flash->error(__('The user could not be saved. Please, try again.'));
        }
        $this->set(compact('user'));
    }

Do you need more ? Just need to give a simple command in your app folder to generate your CRUD.

give command

bin/cake bake all users

Assumption, users is your database table name. Then you will get add,edit,delete,view. can see this tutorial for see how to give cake bake command

Alimon Karim
  • 4,354
  • 10
  • 43
  • 68
  • thanks for your answer it solved most of it but save data to database would i get a response for that as well. pls thanks. – Prabhakar Siddhant Jan 21 '20 at 10:56
  • You will save data in database using method save(), you don't need write insert query. Insert query manage by save. – Alimon Karim Jan 21 '20 at 11:05
  • ok i get that so i let code flow but i was not able to save data because went to : $this->Flash->error(__('The user could not be saved. Please, try again.')); – Prabhakar Siddhant Jan 21 '20 at 11:08
  • This is unable to save then you got error. Here may have lots of problem. see in logs/error.log for details. – Alimon Karim Jan 21 '20 at 11:12
  • there is no error as such but only flash message but i'll read code still and get back. thanks. – Prabhakar Siddhant Jan 21 '20 at 11:19
  • Is it saving data ? – Alimon Karim Jan 21 '20 at 11:20
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/206350/discussion-between-alimon-karim-and-prabhakar-siddhant). – Alimon Karim Jan 21 '20 at 11:21
  • Hi, i need a solution with CakePHP do not feel like posting a question about it because i can get a response so give a code to make two table association come together as one variable what code do i write for clean and simple implementation of code to get table data from two table i'll post a question to elaborate but it would put a my concern forward. – Prabhakar Siddhant Jan 30 '20 at 04:56