在CakePHP3中加载自定义类 [英] Loading custom class in CakePHP3

查看:55
本文介绍了在CakePHP3中加载自定义类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在CakePHP3项目中加载一个自定义类,尽管我似乎无法找出我所缺少的东西.

I am trying to load a custom class in my CakePHP3 project, although I can't seem to find out what I am missing.

我有一个文件夹 src/Library ,其中包含 Config.php :

I have a folder src/Library with Config.php in it:

<?php

namespace App\Library;

/**
 * Class containing CONST values for important settings
 *
 * @version 1.0
 * @author berry
 */
class Config
{
    const UPLOAD_DIRECTORY = './upload/';
}

我将 use App \ Library \ Config; 放在我的 PicturesController 中,Visual Studio甚至将其识别为有效类(我可以访问 const 通过智能感知

I put use App\Library\Config; in my PicturesController, which Visual Studio even recognizes as a valid class (I can access the const through intellisense)

这是我的控制人:

<?php
namespace App\Controller;

use App\Controller\AppController;
use Cake\Filesystem\Folder;
use Cake\Filesystem\File;
use App\Library\Config;

/**
 * Pictures Controller
 *
 * @property \App\Model\Table\PicturesTable $Pictures
 */
class PicturesController extends AppController
{
    public function upload()
    {
        if($this->request->is('post'))
        {
            $oConfig = new Config();

            $oUploadDir = new Folder($oConfig::UPLOAD_DIRECTORY);

            debug($oUploadDir);

            $aFile = $this->request->data('submittedfile');
        }

    }

因此,尽管我的IDE甚至注册了该类(并告诉我我正在正确使用它),但我还是在浏览器中抛出了找不到类'App \ Library \ Config'.

So despite my IDE even registering the class (and telling me I'm using it correctly) I get Class 'App\Library\Config' not found thrown in the browser.

推荐答案

我将名称从Library更改为Berry(我的名字).

I changed the name from Library to Berry (My first name).

显然,您不能将其称为图书馆".可能在Cake的其他地方使用了.

Apparently you can't call it Library. Probably used somewhere else in Cake.

这篇关于在CakePHP3中加载自定义类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆