php - 未找到 Laravel 5.0 类
问题描述
我在我正在处理的项目中有一个名为“语言”的课程,您可以选择页面所在的语言并确定当前选择的语言。我正在更新我的 laravel 并在 5.0 更新时遇到了一个问题,它不再找到我的 Language 类。我认为这是一个自动加载器问题,但我不是 100% 确定它。
这是我的文件顺序
Language.php是找不到的类,找不到的文件是“resources\views\home.php”下的home.php
这是我的 Language.php 文件
<?php
namespace App\Libaries;
use Illuminate\Support\Facades\Facade;
class Language extends Facade
{
private static $primary;
private static $secondary;
protected static function getFacadeAccessor() { return 'Language'; }
public static function init()
{
if (strlen(Request::segment(1)) === 2) {
self::$primary = Request::segment(1);
} elseif (strlen(Request::segment(1)) !== 2) {
self::$primary = 'fi';
}
if (self::$primary === 'ee' || self::$primary === 'en') {
self::$secondary = 'fi';
} elseif (self::$primary !== 'en' && self::$primary !== 'ee') {
self::$secondary = 'en';
}
}
public static function getsecondary()
{
return self::$secondary;
}
public static function getprimary()
{
return self::$primary;
}
public static function getAllLanguages()
{
return array(
'fi' => 'Suomeksi',
'en' => 'In English',
'se' => 'På Svenska',
'de' => 'Deutsch',
'ru' => 'по-русски',
'ee' => 'Eesti keeles',
'pl' => 'Po Polsku',
'fr' => 'En Français',
'es' => 'En Español',
'cn' => '中文',
'cs' => 'Čeština',
'sk' => 'Slovenčina',
'nl' => 'Nederlands',
'jp' => 'Japanese',
);
}
public static function line($key)
{
if (Lang::has($key, self::$primary) === false) {
return mbUcfirst(Lang::get($key, array(), self::$secondary));
}
return mbUcfirst(Lang::get($key, array(), self::$primary));
}
}
function mbUcfirst($string)
{
return mb_strtoupper(mb_substr($string, 0, 1))
. mb_substr($string, 1);
}
这是我的 home.php 文件
<?php
namespace App\resources\views;
use App\Libraries\Language
?>
<h1><?=Language::line('common.index')?></h1>
<div id="home-description-text">
<?=Page::getPage('index')?>
</div>
<div id="home-description">
<a href="<?=$language?>/project">
<span id="home-description-title"><?=Language::line('home.description_link_label')?></span>
</a>
</div>
<div id="home-history">
<a href="<?=$language?>/history">
<img id="home-history-image" src="/img/home/history.jpg" alt="history" />
<span id="home-history-title"><?=Language::line('home.history_link_label')?></span>
</a>
</div>
<div id="home-map">
<a href="<?=$language?>/map">
<img id="home-map-image" src="/img/home/map.jpg" alt="map" />
<span id="home-map-title"><?=Language::line('home.map_link_label')?></span>
</a>
</div>
<div id="home-destinations">
<a href="<?=$language?>/buildings">
<img id="home-destinations-image" src="/img/home/destinations.jpg" alt="destinations" />
<span id="home-destinations-title"><?=Language::line('home.destinations_link_label')?></span>
</a>
</div>
<div id="home-ebook">
<a href="<?=$language?>/ebook">
<img id="home-ebook-image" src="/img/home/ebook.jpg" alt="ebook" />
<span id="home-ebook-title"><?=Language::line('home.ebook_link_label')?></span>
</a>
</div>
<div class="clear-both">
</div>
这是我的 composer.json 文件
{
"name": "laravel/laravel",
"description": "The Laravel Framework.",
"keywords": ["framework", "laravel"],
"license": "MIT",
"type": "project",
"require": {
"laravel/framework": "5.0.*",
"laravelcollective/html": "~5.0"
},
"require-dev": {
"phpunit/phpunit": "~4.0",
"phpspec/phpspec": "~2.1"
},
"autoload": {
"classmap": [
"database/migrations",
"database/seeds",
"app/Http/Controllers",
"app/Libraries/Language.php",
"app/models",
"app/commands",
"resources/views",
"resources/lang",
"vendor/laravel/framework/src/Illuminate/Contracts/View"
],
"psr-4": {
"App\\": "vv5/"
}
},
"autoload-dev": {
"classmap": [
"tests/TestCase.php"
]
},
"scripts": {
"post-install-cmd": [
"php artisan clear-compiled",
"php artisan optimize"
],
"post-update-cmd": [
"php artisan clear-compiled",
"php artisan optimize"
],
"post-create-project-cmd": [
"php -r \"copy('.env.example', '.env');\"",
"php artisan key:generate"
]
},
"config": {
"preferred-install": "dist"
}
}
如果格式不好,请提前抱歉,这是我第一次发布堆栈溢出。
我对命名空间仍然很陌生,所以我确定我可能缺少一个明显的东西,但我似乎无法自己弄清楚。希望这篇文章会有所帮助,在此先感谢。
解决方案
推荐阅读
- javascript - 这个 3D Cube 在 Chrome Vs Safari 中的旋转方式不同
- serial-port - 串口 sysbuffer outSize 超过 fconfigure 指定的值
- bash - 将二进制文件读入bash中的变量
- javascript - JQuery:获取一系列复选框以进行验证
- python - 解压ripemd160导致python
- c# - c# CSOM批量获取SharePoint列表
- r - 多条件内连接r数据表
- lambda - Kotlin:Lambdas、范围、映射、过滤和减少/折叠
- node.js - 导入 Node.js 模块函数,而不调用它
- android - 重复功能以每秒从服务器调用数据