cakephp在屏幕上打印功能结果

时间:2012-12-10 10:58:31

标签: php cakephp

我正在阅读cakebook,但仍然不明白。我在向数据库添加数据时遇到问题,所以我想查看基本添加功能的结果:

public function add() {
    if ($this->request->is('post')) {
        $this->Ficha->create();
        if ($this->Ficha->save($this->request->data)) {
            $this->Session->setFlash('Your post has been saved.');
            //$last_id=$this->Ficha->getLastInsertID();
            $this->redirect(array('action' => 'preencher_ficha'),$last_id);
        } else {
            $this->Session->setFlash('Unable to add your post.');
        }
        print_r($this->Ficha->save);
    }
}

add.ctp文件

<?php
echo $this->Form->create('Ficha', array('action' => 'index'));
echo $this->Form->input('cod_produto', array('label' => 'Código Produto:'));
echo $this->Form->input('nome_produto', array('label' => 'Nome Produto:'));
echo $this->Form->input('versao', array('label' => 'Versão:'));
echo $this->Form->input('data_ficha', array('label' => 'Data:'));
//echo $this->Form->input('body', array('rows' => '3'));
echo $this->Form->end('Criar Ficha');
?>

为此,我想使用$ debug或$ print_r,以便在提交表单后,cakephp会告诉我问题所在,但我没有正确使用它或者可能在错误的“部分”。任何人都可以告诉我应该使用哪个var来打印,以及我应该在那个输出的var之间有什么来打印screnn上的add函数的结果?

谢谢!

1 个答案:

答案 0 :(得分:1)

您可以在此处进行一些调试:

public function add() {
    pr($this->request->data); // to get the data from the form
    die; // if you don't want it to continue to your save function
    if ($this->request->is('post')) {
        $this->Ficha->create();
        if ($this->Ficha->save($this->request->data)) {
            $this->Session->setFlash('Your post has been saved.');
            //$last_id=$this->Ficha->getLastInsertID();
            $this->redirect(array('action' => 'preencher_ficha'),$last_id);
        } else {
            $this->Session->setFlash('Unable to add your post.');
        }
    }
}

OR:

public function add() {
    if ($this->request->is('post')) {
        $this->Ficha->create();

        pr($this->Ficha->save($this->request->data)); // to print the result of the save
    }
}