我陷入了URI的困境,这个URI不会重定向到我创建的页面。我有页面
索引页工作正常,但是当我尝试重定向到其他页面时,它将引发异常
class Print(object)
def __init__(self):
self.printer = 'something'
def pretty_print(self, text):
print('Pretty {}'.format(text))
class Report(object)
def __init__(self):
self.var1 = 1
self.var2 = 2
def return_sum(self):
return self.var1 + self.divide_by_two(self.var1 + self.var2)
class MasterClass(Report, Print):
def __init__(self):
Report.__init__(self)
Print.__init__(self)
self.execute()
def execute(self):
sum = self.return_sum()
def divide_by_two(self, number):
return number / 2
如果问题无法理解,我还将录制视频以描述我的问题。 https://www.useloom.com/share/5199399f3b5f42dd9c589a47dad0738f
我尝试了很多事情来对代码进行更改。当我将var_dump()转换为uri函数时,它会向我返回错误的URI的多个链接
我的route.php文件
Fatal error: Uncaught Exception: No route defined for this URI. in /opt/lampp/htdocs/learnPHP/core/Router.php:21 Stack trace: #0 /opt/lampp/htdocs/learnPHP/index.php(6): Router->direct('about/about/cul...') #1 {main} thrown in /opt/lampp/htdocs/learnPHP/core/Router.php on line 21
index.php
<?php
$router->define([
'' => 'controllers/index.php',
'about' => 'controllers/about.php',
'about/culture' => 'controllers/about-culture.php',
'contact' => 'controllers/contact.php'
]);
.htaccess
$database = require 'core/bootstrap.php';
require Router::load('routes.php')
->direct(Request::uri());
Request.php
RewriteEngine On
AddType text/css .css
AddType text/javascript .js
RewriteCond %{REQUEST_URI} !(\.css|\.js|\.png|\.jpg|\.gif|robots\.txt)$ [NC]
RewriteRule ^.*$ index.php [END]
<?php
class Request
{
public static function uri()
{
$uri = (substr($_SERVER['REQUEST_URI'],10));
$removeSlash = rtrim($uri, '/');
return var_dump($removeSlash);
}
}
请单击链接以查看生成的图像https://prnt.sc/n3ar12
答案 0 :(得分:0)
在视频中显示的导航中,您似乎正在做
<a href="">Home</a>
代替
<a href="/learnPHP/">Home</a>
请在https://www.w3schools.com/html/html_filepaths.asp
中找到有关相对和绝对URL的更多信息。您需要编辑views / partials / nav.php并链接正确的起始路径,在您使用的情况下,正确的起始路径为'/ learnPHP /',如果不使用子目录,则为'/'。我也强烈建议您为所有其他导航项目使用以“ /”开头的网址。