php Laravel 框架之建立后台文件夹 二
在前面的章节中我们讲解过如何在 Laravel框架中建立后台文件夹.
php Laravel 框架之建立后台文件夹
现在我们再添加一块内容.是关于自动加载的部分.
在我们app目录中还有个start目录.它里面这样写道:
In addition to using Composer, you may use the Laravel class loader to
load your controllers and models. This is useful for keeping all of
your classes in the "global" namespace without Composer updating.
我翻译一下:除了使用Composer,你还可以使用Laravel的类加载器来加载你的控制器和模型.
这对于让你的类在不使用Composer updating 的情况下处于全局的名字空间中非常有用.
我们这里有一个code fragment
ClassLoader::addDirectories(array(
app_path().'/commands',
app_path().'/controllers',
//app_path().'/controllers/admin',
app_path().'/models',
app_path().'/database/seeds',
));
对,很熟悉,这些文件夹都是我们经常用到的文件夹,控制器,命令.模型,数据库种子
这些文件夹中的内容就是可以自动加载到全局名字空间中的.
但是还多了一个我注释的内容.这个内容的目的是干什么呢..
就是让我们controllers目录中的admin中的控制器也同样具有全局的名字空间.这样我们就可以直接在路由表中通过
我们的控制器名字来接收了.
我测试了一下,确实成功了,而不再需要compoer dumpautoload
但是还是有个问题,如果admin文件夹中有一个控制器和外面的名字相同该怎么办?
我也同样做了一个实验,最终发现,它只会选择其中之一,至于到底选择哪一个,就看我们上面的那个加载的顺序了.
如果是
app_path().'/controllers',
app_path().'/controllers/admin',
那么外部的控制器有效,否则的话,admin文件夹里面的控制器有效.
结合之前写的这么多.其实最保险,也高大上的方法就是使用 名字空间.
但是编写起来也会更加复杂一点咯...小项目可以考虑我们的方法.大不了注意一下,别让这些控制器冲突就好了.
又不是没办法控制.对吧.
Do one thing at a time,and do well.
Best Wishes.

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Evaluating the cost/performance of commercial support for a Java framework involves the following steps: Determine the required level of assurance and service level agreement (SLA) guarantees. The experience and expertise of the research support team. Consider additional services such as upgrades, troubleshooting, and performance optimization. Weigh business support costs against risk mitigation and increased efficiency.

The learning curve of a PHP framework depends on language proficiency, framework complexity, documentation quality, and community support. The learning curve of PHP frameworks is higher when compared to Python frameworks and lower when compared to Ruby frameworks. Compared to Java frameworks, PHP frameworks have a moderate learning curve but a shorter time to get started.

The lightweight PHP framework improves application performance through small size and low resource consumption. Its features include: small size, fast startup, low memory usage, improved response speed and throughput, and reduced resource consumption. Practical case: SlimFramework creates REST API, only 500KB, high responsiveness and high throughput

According to benchmarks, for small, high-performance applications, Quarkus (fast startup, low memory) or Micronaut (TechEmpower excellent) are ideal choices. SpringBoot is suitable for large, full-stack applications, but has slightly slower startup times and memory usage.

Writing clear and comprehensive documentation is crucial for the Golang framework. Best practices include following an established documentation style, such as Google's Go Coding Style Guide. Use a clear organizational structure, including headings, subheadings, and lists, and provide navigation. Provides comprehensive and accurate information, including getting started guides, API references, and concepts. Use code examples to illustrate concepts and usage. Keep documentation updated, track changes and document new features. Provide support and community resources such as GitHub issues and forums. Create practical examples, such as API documentation.

Choose the best Go framework based on application scenarios: consider application type, language features, performance requirements, and ecosystem. Common Go frameworks: Gin (Web application), Echo (Web service), Fiber (high throughput), gorm (ORM), fasthttp (speed). Practical case: building REST API (Fiber) and interacting with the database (gorm). Choose a framework: choose fasthttp for key performance, Gin/Echo for flexible web applications, and gorm for database interaction.

A problem that Windows 11 users may encounter when using computers: users cannot delete certain folders on the desktop. So what should I do if the main folder on the Win11 desktop cannot be deleted? Sometimes you encounter the problem that folders on the desktop cannot be deleted. This is because the folder is occupied by system processes or certain applications, or due to permission settings and other reasons. Let this site carefully explain it for users. Let’s introduce the analysis of the problem that the main folder on the Win11 desktop cannot be deleted. What should I do if I can’t delete the desktop folder? 1. Restart the computer using safe mode; 2. Check and modify permission settings; 3. Use command prompt to force deletion; 4. Use third-party software; 5. Check for disk errors; 6. Consider system restore. Confirm that the folder usage is correct

In Go framework development, common challenges and their solutions are: Error handling: Use the errors package for management, and use middleware to centrally handle errors. Authentication and authorization: Integrate third-party libraries and create custom middleware to check credentials. Concurrency processing: Use goroutines, mutexes, and channels to control resource access. Unit testing: Use gotest packages, mocks, and stubs for isolation, and code coverage tools to ensure sufficiency. Deployment and monitoring: Use Docker containers to package deployments, set up data backups, and track performance and errors with logging and monitoring tools.
