繁体   English   中英

cakephp在屏幕上显示功能的结果

[英]cakephp print on screen result of function

我在看蛋糕本,但还是听不懂。 我在将数据添加到数据库时遇到问题,因此我想检查基本添加功能的结果:

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,以便在提交formphp表单后向我显示问题出在哪里,但我没有正确使用它,或者可能在错误的“部分”中。 谁能告诉我应该使用哪个变量来打印以及在输出变量的()之间应该有什么才能在screnn上打印add函数的结果?

谢谢!

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

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.');
        }
    }
}

要么:

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
    }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM