【发布时间】:2015-01-12 13:49:57
【问题描述】:
好的,在 laravel 4 中,如果我想添加自己的自定义类,例如:library\myFunction.php,那么我执行以下步骤:
- 将“myFunctions.php”添加到 app/library/myFunctionosn.php
- 在 app/start/global.php 中,在 ClassLoader::addDirectories(array() 中,我添加 app_path().'/library',
- 为了在我的刀片视图中调用它,我添加了以下代码
<?php
$FmyFunctions1 = new myFunctions;
$is_ok1=($FmyFunctions1->is_ok());
?>
- app/library/myFunctions.php 的内容是:
<?php namespace App\library {
class myFunctions {
public function is_ok() {
return 'myFunction is OK';
}
}
}
?>
而且它有效。
但是如何在 Laravel 5 中这样做???
PS : 我看了What are the best practices and best places for laravel 4 helpers or basic functions?
并尝试将 "app/library/", 添加到 自动加载数组 并运行 composer dum-autoload ,但它一直给我错误:
在 xxxx 行 xx 中出现 FatalErrorException:找不到类“myFunctions”
我也已经在尝试使用了:
composer update
composer dump-autoload
php artisan dump
php artisan clear-compiled
php artisan dump-autoload
php artisan optimize
php artisan route:clear
php artisan route:scan
php artisan route:list
但是还是不行……
【问题讨论】:
-
尝试运行 composer dump-autoload
-
已经用了,也不能用
-
在 composer.json 中使用命名空间自动加载
-
已经用了,但不起作用...
-
更新了我的问题