gpt4 book ai didi

laravel-4 - 拉拉维尔 : Log:info in repository not printing values from Input

转载 作者:行者123 更新时间:2023-12-02 22:20:24 26 4
gpt4 key购买 nike

Laravel 新手,因此想了解这一点。

Log::info() 是否不允许打印某些信息?它默默地死去,因此想知道这是否是我尚未学习的一些 Laravel 规则..

我的 HTML 表单是这样的:

<form>
<input type="hidden" name="val[name]">
<input type="hidden" name="val[address]">
</form>

我的 Ajax 函数只是创建一个 formData 并将其发送到后端。

$.ajax({
url : baseUrl + 'update/' + id,
type : 'POST',
data : new FormData(this),
contentType : false,
cache : false,
processData : false,
success : function(
}
});

我的 Controller 打印/Input::get('val') 没有问题。

我的存储库

public function update user($id, $val)
{
Log::info('reached forward() in the repository');

$post = $this->findById($postID);
Log::info('Going to print the values now');
Log::info('Val : ', $val);
//Log::info('Post-ID : ', $id);
Log::info('-----------------');

Log::info('Extracting the VAL to regular variables');


$expected = [
'name' => '',
'address' => []
];

/**
* @var $name
* @var $address
*/
extract($val = array_merge($expected, $val)); // create $name & $address

Log::info('After extraction'); // Gets printed

if($name == 'Tim')
{
Log::info('Name entered is in fact Tim'); // This does get printed
}
Log::info('Name sent is : ', $name); // **This is never printed**
Log::info('Printed Name'); // **This is never printed**
}

我做错了什么,还是 Laravel 的 Log 函数不允许打印它们?
顺便说一句,我在 laravel.log 或 php 错误日志中没有看到任何错误。

最佳答案

不,关于日志记录的工作方式没有特殊规则 - 它记录作为第一个参数传递的任何字符串 + 可能作为第二个参数传递的上下文数组。

让我们看看您的代码:

Log::info('Name entered is in fact Tim'); // This does get printed
Log::info('Name sent is : ', $name); // **This is never printed**
Log::info('Printed Name'); // **This is never printed**

第一行被打印,因为字符串被传递给 info() 方法。第二次调用无效,因为您传递了 2 个字符串参数。如果您打算连接 发送的名称是:$name,则需要使用点而不是逗号:

Log::info('Name sent is : ' . $name); // Now this will get printed

第三行不打印的原因是第二行由于第二个参数的类型无效而导致 PHP 崩溃。它需要一个数组,但它得到的是字符串。

关于laravel-4 - 拉拉维尔 : Log:info in repository not printing values from Input,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31627980/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com