小编Vin*_*des的帖子

"date():依靠系统的时区设置是不安全的......"

当我请求在服务器上将PHP版本从5.2.17 更新到PHP 5.3.21 时,我收到此错误.

<div style="border:1px solid #990000;padding-left:20px;margin:0 0 10px 0;">

<h4>A PHP Error was encountered</h4>

<p>Severity: Warning</p>
<p>Message:  date(): It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'America/New_York' for 'EDT/-4.0/DST' instead</p>
<p>Filename: libraries/Log.php</p>
<p>Line Number: 86</p>

</div>
Warning: …
Run Code Online (Sandbox Code Playgroud)

php timezone

351
推荐指数
10
解决办法
55万
查看次数

Laravel Livewire 组件刷新后不会自动刷新/重新加载

所以,我目前在我的一个项目中使用Laravel Livewire。但是,当我尝试通过 magic mathod 从一个组件向另一个组件发出事件时$refresh,它刷新了(在 xhr 请求中获得了 dom)整个组件,但前端没有实时更新。

ProductReviewForm.php 成分:

public function save()
{
    //some functionalities .... 
    $this->emit('reviewSectionRefresh');
}
Run Code Online (Sandbox Code Playgroud)

ProductReviewSection.php 成分:

protected $listeners = [
    'reviewSectionRefresh' => '$refresh',
];

public function render()
{
    $this->review_lists = ProductReview::orderBy('id', 'DESC')->get();

    return view('livewire.desktop.product-review-section');
} 
Run Code Online (Sandbox Code Playgroud)

所以我想reviewSectionRefresh在我save()从第一个组件调用函数时发出要发出的事件,这应该被$listeners其他组件监听。这工作正常。同样在 xhr 中,我得到了刷新的 dom,但前端的组件没有更新。希望任何与 Livewire 合作的人都可以对此有所帮助。

php laravel laravel-livewire

14
推荐指数
1
解决办法
2万
查看次数

Laravel Livewire 分页

Laravel - 8.6.0 (Jetstream),Livewire - 2.2.7

除其他外,我有两个简单的表格,其中包含使用 Livewire 呈现的搜索输入。两个 Livewire 组件的逻辑几乎相同,主要区别在于 DB 查询格式。在一张表中一切正常(搜索、分页),但在第二张表中存在分页问题。

怎么了? 当我点击分页链接时(例如从第一页 gotoPage(2)),请求被发送,浏览器中的 url 更改为正确的查询字符串,收到响应,但响应中没有 HTML 部分,DOM 中没有变化和分页显示第一页处于活动状态。如果我手动刷新页面,表格会显示第 2 页的数据,之后我什至可以获取下一页或上一页的新数据,但只能在初始页面刷新后获取一次。如果我再次单击分页链接,则没有 HTML 数据响应,也没有 DOM 更改...

我尝试了什么?

  1. 我已经阅读了 Livewire 文档,尝试了“疑难解答”部分中的所有建议解决方案。
  2. 我多次检查我的代码,比较了 Livewire 组件和 Blade 视图,都没有发现一些明显的错误。
  3. 在过去的 10 天里,我一直在 SO、Livewire 论坛、Laracast 论坛上寻找答案,...找到了一些好的建议,尝试了其中的大部分,但没有一个能解决我的问题。
  4. 消除了数据库查询逻辑导致一些问题的可能性,即使我不使用复杂的记录过滤(例如,如果我只是对所有记录进行分页 - Model::all()->paginate(10)),问题也会存在。
  5. 有问题的表通过单选按钮进行了一些额外的记录过滤,我暂时删除了它,但问题仍然存在。

工作 Livewire 组件和 Blade 视图的代码:

<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Factories\HasFactory;

class Extension extends Model
{
    use HasFactory;
    protected $guarded = [];

    public function user()
    {
        return $this->belongsTo('App\Models\User', 'directory', 'ext');
    }

    public static …
Run Code Online (Sandbox Code Playgroud)

php pagination laravel laravel-livewire

5
推荐指数
1
解决办法
5223
查看次数

Livewire 组件插入另一个 Livewire 组件

我有一个包含几张卡片的 Livewire 概述组件。在这些卡中,有一个 livewire 表单,但是当我将该表单包含到概述组件中时,我的整个 livewire 停止工作。

我添加到概述组件文件中的唯一一行是:

@livewire('apply-form')

当我删除该 livewire 方法时,一切都会再次正常工作,但我也需要在我的概述组件中使用该表单。

我做错了什么吗,或者有人可以帮我解决这个奇怪的“错误”吗?

不知道我的 livewire 版本,但资产已过时。

Livewire 也没有给出任何错误。

主要组件,其中包含导致其余组件崩溃的其他组件

导致其余部分崩溃的 Livewire 组件的代码:


namespace App\Http\Livewire;

use Illuminate\Support\Facades\Mail;
use Livewire\Component;
use App\Mail\ApplyMail;
use Livewire\WithFileUploads;

class ApplyForm extends Component
{
    use WithFileUploads;

    public $voornaam;
    public $achternaam;
    public $woonplaats;
    public $geboortedatum;
    public $emailadres;
    public $telefoonnummer;
    public $vacaturenaam;
    public $cv;

    protected $rules = [
        'voornaam' => 'required|max:10',
        'achternaam' => 'required|max:10',
        'woonplaats' => 'required|max:10',
        'geboortedatum' => 'required|date',
        'emailadres' => 'required|e-mail',
        'telefoonnummer' => 'required|numeric',
        'vacaturenaam' => 'required', …
Run Code Online (Sandbox Code Playgroud)

php laravel eloquent laravel-livewire

5
推荐指数
1
解决办法
3688
查看次数

Livewire 不重新渲染

我不知道我错过了什么,但我遵循了每一步,但它没有重新渲染视图。

这是我的 livewire 组件类:

use Livewire\Component;

class HelloWorld extends Component
{
    public $message = 'Hello, world!';

    public function render()
    {
        return view('livewire.hello-world');
    }
}

Run Code Online (Sandbox Code Playgroud)

这是实时线视图:

<input type="text" wire:model="message">{{ $message }}
Run Code Online (Sandbox Code Playgroud)

当我在输入框中输入时,我看到 XHR 请求正在发送,但视图没有更新。我在这里缺少什么?几个小时以来,我一直在四处寻找答案。

php laravel laravel-livewire

4
推荐指数
1
解决办法
1403
查看次数

如何将查询的第一个结果与其他结果分开?

我想将第一个PDO结果数组与其他数组分开.这是我的尝试:

$iterator = 1;
while($results = $stmt->fetch(PDO::FETCH_ASSOC) and $iterator == 1){
    /* I need just first row here */
    print_r($results);
    $iterator++;
}

while($results = $stmt->fetch(PDO::FETCH_ASSOC)){
    /* I need other rows here */
    print_r($results);
}
Run Code Online (Sandbox Code Playgroud)

只有首先while()在我的代码中执行(上面的代码总是只打印查询的第一个结果).那么,我该如何解决呢?

注意:我不想用fetchAll();.

php mysql arrays pdo

3
推荐指数
1
解决办法
114
查看次数

Laravel livewire - 如何将用户的地理坐标传递给 livewire 组件

我正在尝试将用户的地理坐标(纬度和经度)发送到 livewire 组件以加载附近的地方。但是我无法发送它,因为它们是 javascript 变量。问题是如何将 javascript 变量发送到 livewire 组件?

这是我到目前为止所做的。

# home.blade.php

@extends('layouts.app')

@section('content')
    <script>
        var latitude;
        var longitude;
        navigator.geolocation.getCurrentPosition(
            function success(pos) {
                var loc = pos.coords;
                latitude = loc.latitude;
                longitude = loc.longitude;
            }, 
            function error(err) {
                // console.warn(`ERROR(${err.code}): ${err.message}`);
                $.getJSON('https://ipinfo.io/geo', function(response) { 
                    var loc = response.loc.split(',');
                    latitude = parseFloat(loc[0]);
                    longitude = parseFloat(loc[1]);
                });
            }, options
        );
    </script>
    @livewire('nearby')
@endsection
@livewireScripts
Run Code Online (Sandbox Code Playgroud)
# Nearby.php 

namespace App\Http\Livewire;

use Livewire\Component;
use Livewire\WithPagination;
use App\Listing;

class Nearby extends Component
{
    use WithPagination;

    public function …
Run Code Online (Sandbox Code Playgroud)

php laravel laravel-livewire

2
推荐指数
1
解决办法
3855
查看次数

Laravel Livewire json 响应

我在使用 Livewire 将数据从 api 响应传递到组件刀片文件时遇到严重问题。起初,在我点击的那一刻,它加载得很好。下拉菜单会在下面引发错误。

Livewire 在尝试水合[注册]组件时遇到损坏的数据。确保 Livewire 组件的 [name, id, data] 在请求之间未被篡改。

我有一个正在加载职业的下拉列表,一开始加载得很好,但是当我从下拉列表中选择某些内容时,它会抛出该错误。

下面是我的组件代码

<?php

namespace App\Http\Livewire;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Http;
use Guzzle\Http\Exception\ClientErrorResponseException;
use Livewire\Component;

class SignUp extends Component
{
    public $response = 0;
    public $data;
    //get all professions and their related prefixes
    public $professions;
    public $profession_id;
    public $prefix;

    public function mount()
    {
        $response = Http::get('http://localhost:8000/api/sign_up');
        $collection = json_decode($response);
        $this->professions = collect($collection->professions);
    }

    public function hydrate()
    {
        $response = Http::get('http://localhost:8000/api/sign_up');
        $collection = json_decode($response);
        $this->professions = collect($collection->professions);
    }


    public function …
Run Code Online (Sandbox Code Playgroud)

php laravel laravel-livewire

2
推荐指数
1
解决办法
7425
查看次数

选择多个实体学说

我正在尝试执行以下查询:

$qb = $this->getEntityManager()->createQueryBuilder();
$referredUsers = $qb->select(['referred', 'referral', 'match'])
    ->from('ProjectContestBundle:UserParticipation', 'up')
    ->innerJoin('ProjectUserBundle:User', 'referred', 'WITH', 'up.user = referred')
    ->innerJoin('ProjectUserBundle:User', 'referral', 'WITH', 'up.referral = referral.referralCode')
    ->innerJoin('ProjectContestBundle:UserParticipation', 'upr', 'WITH', 'upr.user = referral')
    ->innerJoin('ProjectMatchBundle:Match', 'match', 'WITH', 'match.owner = referred')
    ->where('up.contest = :contest')->andWhere('upr.contest = :contest')
    ->setParameter('contest', $contest)
    ->getQuery()->getResult();
Run Code Online (Sandbox Code Playgroud)

我期望结果是一个行数组,其中每一行都是 type [User, User, Match],但是 Doctrine 返回一个带有混合实体内容的普通数组。

然后我尝试通过以下方式使其更简单:

$qb = $this->getEntityManager()->createQueryBuilder();
$referredUsers = $qb->select(['referred.id', 'referral.id', 'match.id'])
    ->from('ProjectContestBundle:UserParticipation', 'up')
    ->innerJoin('ProjectUserBundle:User', 'referred', 'WITH', 'up.user = referred')
    ->innerJoin('ProjectUserBundle:User', 'referral', 'WITH', 'up.referral = referral.referralCode')
    ->innerJoin('ProjectContestBundle:UserParticipation', 'upr', 'WITH', 'upr.user = referral') …
Run Code Online (Sandbox Code Playgroud)

php symfony doctrine-orm

1
推荐指数
1
解决办法
1万
查看次数