Target class [StaticPagesController] does not exist.

1.一开始我是在跟着教程走的,按照教程然后报一个错

Target class [StaticPagesController] does not exist.

然后再网上查了好多,最终这个博客主解决了

Laravel Target class [控制器名称] does not exist.完美解决!_laravel10 resource target class-CSDN博客

在这个文件夹中app/Providers/RouteServiceProvider.php加一段话

protected $namespace = 'App\\Http\\Controllers';

这行代码指定了控制器类的默认命名空间为App\Http\Controllers。

这样,在路由文件中定义的路由,如果没有指定命名空间,就会自动使用该默认命名空间下的控制器类。

这个一般文件自己有的,但是可能因为版本问题,我的咩有。

然后就出来效果了,我真的是开心坏了


主页页面测试可以出现了,就迫不及待测试来一下帮助页和关于页就又又又出现报错!!!

2.就是说除了主页内容可以出来,其他页面一直报错

Not Found The requested URL /help was not found on this server. Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.

官网突然只能打开首页 再点击其他所有链接都报404错误(NOT FOUND The requested URL was not found on this server)

一开始认为是服务器配置出了问题 于是开始搞配置文件 重启apache 甚至重启服务器 但都于事无补

最后突然看到一篇文章说是网站少了 重写文件.htacces这个文件之后会发生这种情况,

然后我去网站根目录去查看 果然少了.htacces这个文件 从本地上传上来之后 问题迎刃而解了

这是我在public文件外面的.htaccess文件的内容,一般这个内容都是一样的,直接复制粘贴别的文件的也可以

SetEnvIf Origin "^http(s)?://(.+\.)?(submit.magazine.ubandev.com|localhost:8080)$" origin_is=$0

Header always set Access-Control-Allow-Origin %{origin_is}e env=origin_is

Header set Access-Control-Allow-Credentials true

Options +FollowSymLinks -Indexes

RewriteEngine On

RewriteCond %{HTTP:Authorization} .

RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

RewriteCond %{REQUEST_FILENAME} !-d

RewriteCond %{REQUEST_FILENAME} !-f

RewriteRule ^ index.php [L]

<IfModule mod_headers.c>

Header set Access-Control-Allow-Origin "*"

</IfModule>

解决“NOT FOUND The requested URL was not found on this server” - luckylou - 博客园

根据这个人的博客解决了一半(因为没有注意是网站根目录,我在整个文件的根目录配置的.htacces),所以又又又又又又又报错啦!!!!!!!


3.因为没有注意是网站根目录,我在整个文件的根目录配置的.htacces,所以又又又又又又又报错啦!!!!!!!

Internal Server Error

The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator at admin@example.com to inform them of the time this error occurred, and the actions you performed just before this error.

More information about this error may be available in the server error log.

Additionally, a 500 Internal Server Error error was encountered while trying to use an ErrorDocument to handle the request.

事实上一开始我只注意了最外面的.htaccess,加上之后就报500的错

然后就是才发现在public的路径下面的.htaccess是空的,然后加上

<IfModule mod_rewrite.c>

<IfModule mod_negotiation.c>

Options -MultiViews -Indexes

</IfModule>

RewriteEngine On

# Handle Authorization Header

RewriteCond %{HTTP:Authorization} .

RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

# Redirect Trailing Slashes If Not A Folder...

RewriteCond %{REQUEST_FILENAME} !-d

RewriteCond %{REQUEST_URI} (.+)/$

RewriteRule ^ %1 [L,R=301]

# Send Requests To Front Controller...

RewriteCond %{REQUEST_FILENAME} !-d

RewriteCond %{REQUEST_FILENAME} !-f

RewriteRule ^ index.php [L]

</IfModule>

就哦空空啦!!!!!!!!!

因为.htaccess文件在搭建站点的时候会自动清空,所以在创建站点的时候先打开这个文件

虽然这个文件下的东西大致是不变的,但是还是觉得用它原本的会比较好


4.然后就是我根据这次报错额外的收获啦!!!

1)三个文件的后缀名均为 .blade.php,而不是 .php。

这是因为 Blade 是 Laravel 中提供的一套模板引擎,在 Blade 视图中我们可以使用 Laravel 为这套引擎定义的一些默认方法,并完全兼容 PHP 语法的书写。

在项目运行时,Laravel 会把所有的 Blade 视图进行编译缓存成普通的 PHP 代码,因此你不必担心 Blade 会对应用产生负担。

2)Artisan命令

先是跟着教程php artisan make:controller StaticPagesController生成静态页面控制器:

php artisan make:controller StaticPagesController

自动生成了这些代码,然后我就寻思artisan是个什么东西??????

查了一下下!!!!

感觉就是很方便的东西耶( •̀ ω •́ )y!!!!!                                                       

Artisan

  • 20
    点赞
  • 22
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值