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

Laravel的Controller设置默认变量

WBOY
Release: 2016-06-06 20:33:10
Original
1421 people have browsed it

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

<code>$v = 1;
</code>
Copy after login
Copy after login

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

回复内容:

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

<code>$v = 1;
</code>
Copy after login
Copy after login

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

App\Http\Controllers\Controller 中定义:

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

在任何控制器中调用:

<code>php</code><code>echo parent::$v;
</code>
Copy after login

<code>php</code><code>//config/app.php
'v' => 1,
//controller.php
echo config('app.v');
</code>
Copy after login
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template