尝试在CakePHP中转储对象或数组
在CakePHP上编码时,我试图将对象或数组转储到调试中。我一直在尝试各种各样的命令,但我确实忘记了各种输出。我肯定看到了一个指示对象类型的输出(CakeEmail)和一个数组。不幸的是,我无法重现其中任何一个 下面是我正在使用的代码,其中包含一些注释,用于指示肯定失败的命令尝试在CakePHP中转储对象或数组,php,arrays,cakephp,cakeemail,Php,Arrays,Cakephp,Cakeemail,在CakePHP上编码时,我试图将对象或数组转储到调试中。我一直在尝试各种各样的命令,但我确实忘记了各种输出。我肯定看到了一个指示对象类型的输出(CakeEmail)和一个数组。不幸的是,我无法重现其中任何一个 下面是我正在使用的代码,其中包含一些注释,用于指示肯定失败的命令 public function _sendEmail($template, $replace_content, $to, $from = null) { App::uses('CakeEmail', 'Networ
public function _sendEmail($template, $replace_content, $to, $from = null)
{
App::uses('CakeEmail', 'Network/Email');
$this->Email = new CakeEmail();
//Preparation of variables to insert into Email
$this->Email->to($to);
$this->Email->subject($subject);
$this->Email->emailFormat('both');
//Debugger::log($this->Email); //Worked - Shows certain output in file
//Debugger::dump($this->Email); //Partial - Did not show any output in file, but did not fail to run.
//Debugger::trace($this->Email); //Partial - Did not show any output in file, but did not fail to run.
//Debugger::debug($this->Email); //Failed - function did NOT continue
//dump($this->Email); //FAILED
//trace($this->Email); //FAILED
//debug($this->Email); //Partial - Did not show any output in file, but did not fail to run.
//Debugger::log(">>log: ".$this->Email); //unable to show variable. Only heading string was output to file
//Debugger::dump(">>dump: ".$this->Email); //Partial - Did not show any output in file, but did not fail to run.
//Debugger::trace(">>trace: ".$this->Email); //NOT TESTED
//Debugger::log(Debugger::dump($this->Email)); //Worked - Shows certain output in file - dump returns NULL
//Debugger::log(">>log: headers: ".Debugger::dump($this->Email->getHeaders())); //Worked - Shows certain output in file - dump returns NULL
//Debugger::log(">>log: headers: ".Debugger::dump($Email->getHeaders())); //FAILED - Undefined variable
include 'dkim.php';
$newHeader = AddDKIM($from_email, $to, $subject, $content);
if (!empty($newHeader)) {
Debugger::log ("newHeader is: $newHeader\n;Adding it to email.");
$emailHeaders = $this->Email->getHeaders();
Debugger::log ($emailHeaders);
debug($emailHeaders);
//$emailHeaders = $newHeader.emailHeaders;
//Debugger::log($this->Email->getHeaders());
debug ($emailHeaders);
}
else
Debugger::log ("No new Header to Add.");
$this->Email->send($content);
}
我并不完全熟悉CakePHP,但您可以使用print_r($variable,true),它以字符串形式返回变量的转储。然后,您可以在日志函数中使用它
Debugger::log(“>>log:”.print\r($this->Email,true))代码>蛋糕具有打印功能,只需执行以下操作:
pr($var_to_debug);
工作起来很有魅力!谢谢