我下载了最新版的Laravel,然后我打算用他来做一个网址导航程序。
我想先做从管理员后台做起,这样可以先添加测试内容,我看了一遍文档,不过感觉很多地方都没有说到的。
1)控制器里面的方法public function showWelcome(){},是不是加上了show前缀就可以访问,如果不加show前缀就不能访问?
2)如果我有一个控制器,文件地址:/app/controllers/InfoControllers.php里面的一个方法 public function showList(){},他的访问地址默认的是多少啊。
开启重写和不开启重写的时候默认的是多少啊。。 是/Info/showList还是/Info/List/
3)关于路由必须绑定。我问了一个人,他告诉我说,每一个网址都必须写一个路由规则。
我比较疑问的是那这样Laravel就没有默认的网址吗。这个默认的网址是如何生成的。。
如果每一个网址都要写一个路由,一个网站里面肯定很多不同的网站,比如分页之类的,管理员后台操作删除之类的,那岂不非常繁琐,每一个网址都要写一条路由。Laravel没有默认的网址格式吗
回复内容:
我下载了最新版的Laravel,然后我打算用他来做一个网址导航程序。
我想先做从管理员后台做起,这样可以先添加测试内容,我看了一遍文档,不过感觉很多地方都没有说到的。
1)控制器里面的方法public function showWelcome(){},是不是加上了show前缀就可以访问,如果不加show前缀就不能访问?
2)如果我有一个控制器,文件地址:/app/controllers/InfoControllers.php里面的一个方法 public function showList(){},他的访问地址默认的是多少啊。
开启重写和不开启重写的时候默认的是多少啊。。 是/Info/showList还是/Info/List/
3)关于路由必须绑定。我问了一个人,他告诉我说,每一个网址都必须写一个路由规则。
我比较疑问的是那这样Laravel就没有默认的网址吗。这个默认的网址是如何生成的。。
如果每一个网址都要写一个路由,一个网站里面肯定很多不同的网站,比如分页之类的,管理员后台操作删除之类的,那岂不非常繁琐,每一个网址都要写一条路由。Laravel没有默认的网址格式吗
Laravel 中的路由可见简单分为2中
常规路由
常规路由或者说是基础路由,支持HTTP Method 或者正则匹配等,还有就是自定义
Route::get('xxx',xxx);
Route::get('xxx/*',xxx);
Route::post('xxx',function(){
xxxx
});
Route::get('/', 'DashBoardController@index');
对应各种HTTP Method目前支持的有
- get
- post
- put
- patch
- options
- delete
匹配路由
- match
- any
自定义
Route::get('user', 'UserController@index');
这里是你访问xxx/user 的时候会调用 UserController中的index 方法
restful 路由
restful 路由又分为2种,第一种没用过不评论,第二种用的很舒服
controller
-
resource
这个使用很方便,直接自动生成 controller,
<code><br>第一步 php artisan controller:make UserController 第二步 routes.php 中 Route::resource('users', 'UserController'); 然后放心调用就好了,这里是调用关系 http://laravel.com/docs/controllers#resource-controllers </code>
回到问题
- 调用和方法名没有关系,但是遵循规范是最好的
- 这个取决于你的router中的定义,
例如你这样定义,那么你访问的就是 http://domain/testRoute::get('test', 'InfoControllers@showList');
- 分页这些其实都是一个路由,然后加参数控制
- 不是,只是表达意思是显示欢迎
- 你需要在路由中规定。比如
Route::get('showlist', '控制器类名称@方法');
, 则 xxx.com/shwolist 指向到这个类中方法 - 没有默认的路由,你仔细看下路由这章, 所有疑问就迎刃而解了
可以结合官方文档再看看这篇文章:http://laravelbase.com/collections/1/36
@trigged
亲一以下写错了:
第一步 php artisan controller:make UserController
正确修改:
第一步 php artisan make:controller UserController

The article explains how to create, implement, and use interfaces in PHP, focusing on their benefits for code organization and maintainability.

The article discusses the differences between crypt() and password_hash() in PHP for password hashing, focusing on their implementation, security, and suitability for modern web applications.

Article discusses preventing Cross-Site Scripting (XSS) in PHP through input validation, output encoding, and using tools like OWASP ESAPI and HTML Purifier.

Autoloading in PHP automatically loads class files when needed, improving performance by reducing memory use and enhancing code organization. Best practices include using PSR-4 and organizing code effectively.

PHP streams unify handling of resources like files, network sockets, and compression formats via a consistent API, abstracting complexity and enhancing code flexibility and efficiency.

The article discusses managing file upload sizes in PHP, focusing on the default limit of 2MB and how to increase it by modifying php.ini settings.

The article discusses nullable types in PHP, introduced in PHP 7.1, allowing variables or parameters to be either a specified type or null. It highlights benefits like improved readability, type safety, and explicit intent, and explains how to declar

The article discusses the differences between unset() and unlink() functions in programming, focusing on their purposes and use cases. Unset() removes variables from memory, while unlink() deletes files from the filesystem. Both are crucial for effec


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

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

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

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software
