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

Laravel的Controller设置默认变量

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-06 20:33:10
Original
1462 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:
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
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template