Home > Backend Development > PHP Tutorial > 命名空间的问题

命名空间的问题

WBOY
Release: 2016-06-06 20:47:01
Original
872 people have browsed it

最近在用thinkphp3.2

在\Application\Content\Logic目录下部署了一个logic类:ArticleLogic.class.php

我在Controller里面调用:

<code class="lang-php">$article_logic = new \Content\Logic\AritcleLogic();
</code>
Copy after login
Copy after login

系统提示:
Class 'Content\Logic\AritcleLogic' not found

是什么问题呢

附AritcleLogic代码

<code class="lang-php">namespace Content\Logic;

class AritcleLogic {

    public function remove() {
        echo 'remove article ...';
    }

    public function save() {

    }

    public function history() {
    }
}
</code>
Copy after login
Copy after login

回复内容:

最近在用thinkphp3.2

在\Application\Content\Logic目录下部署了一个logic类:ArticleLogic.class.php

我在Controller里面调用:

<code class="lang-php">$article_logic = new \Content\Logic\AritcleLogic();
</code>
Copy after login
Copy after login

系统提示:
Class 'Content\Logic\AritcleLogic' not found

是什么问题呢

附AritcleLogic代码

<code class="lang-php">namespace Content\Logic;

class AritcleLogic {

    public function remove() {
        echo 'remove article ...';
    }

    public function save() {

    }

    public function history() {
    }
}
</code>
Copy after login
Copy after login

你写use了么?

建议看看是不是路径因为大小写的问题导致的,如果还不好找问题的话,建议你debug下
ThinkPHP\Library\Think\Think.class.php中找到第162左右

<code class="lang-php">$filename       =   $path . str_replace('\\', '/', $class) . EXT;
</code>
Copy after login

下面增加

<code class="lang-php">if($class == 'Content\Logic\AritcleLogic') {
   //debug_print_backtrace();
   var_dump($filename);exit;
}
</code>
Copy after login

看看实际寻找到哪里去了

命名空间的问题

Related labels:
php
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