我的组件长这个样子:
namespace App\View\Components;
use Illuminate\View\Component;
use App\Http\Controllers;
use Illuminate\Http\Request;
class shopImageContainer extends Component
{
public $image;
public $ph;
public $va;
public $config;
/**
* Create a new component instance.
*@param string $ph
*@param string $va
* @return void
*/
public function __construct($ph, $va, $image)
{
$this->image = $image;
$this->va = $va;
$this->ph = $ph;
$this->config = Controllers\GlobalFunctions::getConfig($ph, $va);
}
/**
* Get the view / contents that represent the component.
*
* @return \Illuminate\Contracts\View\View|string
*/
public function render()
{
return view('components.shop-image-container');
}
}
在我的component.blade中,我有这行/块代码,它会抛出"Undefined variable: config"错误:
@if($config->dd)
<div class="col bg-dark text-center p-3">
<a class="btn btn-primary rounded-0 " href="/download/{{ basename($image) }}" role="button">Download in {{ $config->ddLongEdge }}px</a>
</div>
@endif
看起来构造方法没有被调用(我在方法中尝试使用dd("test"),但是没有输出)。有趣的是,在我的本地环境中它可以工作,但是在服务器上(apache2)无法工作。我在某个地方读到说可能会存在组件的错误,并且服务器的配置可能出了问题,但是在这两种情况下都没有进一步的解决方法。感谢任何帮助。