Home >Backend Development >PHP Tutorial >Laravel的Controller设置默认变量

Laravel的Controller设置默认变量

WBOY
WBOYOriginal
2016-06-06 20:33:101437browse

如果Laravel的每个Controller的每个method,都需要定义一个变量

<code>$v = 1;
</code>

有没有什么简单方法只写一遍?

回复内容:

如果Laravel的每个Controller的每个method,都需要定义一个变量

<code>$v = 1;
</code>

有没有什么简单方法只写一遍?

App\Http\Controllers\Controller 中定义:

<code>php</code><code>protected static $v = 1;
</code>

在任何控制器中调用:

<code>php</code><code>echo parent::$v;
</code>

<code>php</code><code>//config/app.php
'v' => 1,
//controller.php
echo config('app.v');
</code>
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn