Wednesday, September 2, 2015

Re: how to debug on a "add" function of controller

Try to make like this:

            debug($this->request) OR die;
  1. Take a look if inside the $this->request there is a node 'data' with your data is been sent
  2. OR die stops your code after the debug so you can verify if the code is triggered easily
  3. Is your request in fact a POST
  4. Is your data been added to database?  
  5. Is your code in your controller?

On Wed, Sep 2, 2015 at 11:02 AM Raul Magdalena Catala <raulmagdalena@gmail.com> wrote:
hello,

i've inserted a debug($this->request->data) into the add function of my controller but nothing is rendered when i've add some data
code looks like:

    public function add()
    {
        $magazine = $this->Magazines->newEntity();
        if ($this->request->is('post')) {
            debug($this->request->data);
            $magazine = $this->Magazines->patchEntity($magazine, $this->request->data);
            if ($this->Magazines->save($magazine)) {
                $this->Flash->success(__('The magazine has been saved.'));
                return $this->redirect(['action' => 'index']);
            } else {
                $this->Flash->error(__('The magazine could not be saved. Please, try again.'));
            }
        }
        $periodicity = $this->Magazines->Periodicity->find('list', ['limit' => 200]);
        $categories = $this->Magazines->Categories->find('list', ['limit' => 200]);
        $this->set(compact('magazine', 'periodicity', 'categories'));
        $this->set('_serialize', ['magazine']);
    }

what i'm doing wrong?

thanks in advance  

--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.
--
--
Diego Mendonça

--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.

No comments: