简体   繁体   English

如何在控制器中创建目录 - laravel

[英]how to make a directory in controller - laravel

I created a Panel directory inside Controller directory .我在Controller目录中创建了一个Panel目录。

在此处输入图片说明

there is a login function inside AdminController.php AdminController.php里面有一个login功能

class AdminController extends Controller
{
    //


    public function login()
    {
        return 'test';
    }
}

in routes.php I wrote a route like this:routes.php我写了一个这样的路线:

Route::get('/cp/login','Panel\AdminController@login');

but when I run below url I got some errors that there isn't exist this controller :但是当我在 url 下运行时,我得到了一些错误,即不存在此控制器:

http://localhost:8000/cp/login http://localhost:8000/cp/登录

ReflectionException in Route.php line 280: Class App\\Http\\Controllers\\Panel\\AdminController does not exist Route.php 第 280 行中的 ReflectionException:Class App\\Http\\Controllers\\Panel\\AdminController 不存在

Try adding the appropriate namespace to the top of the AdminController file, you will also need to specify the namespace for the Controller class that it extends, as they are under different sub-namespaces.尝试将适当的命名空间添加到AdminController文件的顶部,您还需要为其扩展的Controller类指定命名空间,因为它们位于不同的子命名空间下。

You can read more about PSR-4 autoloading here http://www.php-fig.org/psr/psr-4/ .您可以在http://www.php-fig.org/psr/psr-4/阅读更多关于 PSR-4 自动加载的信息。

Based on the directory structure that you have there it should read根据您在那里拥有的目录结构,它应该读取

<?php

    namespace App\Http\Controllers\Panel

    use App\Http\Controllers\Controller;

    class AdminController extends Controller {

        //..

    }

you should add the namespace to the contorller您应该将命名空间添加到控制器

Change you namespace to将您的命名空间更改为

namespace App\\Http\\Controllers\\Panel;命名空间 App\\Http\\Controllers\\Panel;

Laravel will resolve controllers based on your name spacing, not on your directory structure. Laravel 将根据您的名称间距而不是您的目录结构来解析控制器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM