博客文章的PHP路由系统
我设法创建了一个简单的路由系统,但是我对如何使其更具动态性有些困扰。在这种情况下,我的路由中有一个博客文章,该文章很难编码。如果我在网站上单击一个需要/views/blog/page.php的动态链接,我该如何使系统能够算出page_slug是什么并附加page_slug,以便它可以在不用硬编码链接中进行硬编码的链接工作?
switch ($request) {
case '':
case '/':
require __DIR__ . '/views/index.php';
break;
case '/blog/blog-post-one':
$_GET['page_slug'] = 'blog-post-one';
require __DIR__ . '/views/blog/page.php';
break;
}
我在下面添加了.htaccess文件,以防万一
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]
I have managed to create a simple routing system however I'm a bit stuck on how to make it more dynamic. In this case I have got a blog post set up in my routing which is hard coded. If i click a dynamic link in my website that requires the /views/blog/page.php how can I get the system to work out what the page_slug is and append the page_slug so that it works without hard coding the links into it?
switch ($request) {
case '':
case '/':
require __DIR__ . '/views/index.php';
break;
case '/blog/blog-post-one':
$_GET['page_slug'] = 'blog-post-one';
require __DIR__ . '/views/blog/page.php';
break;
}
I've added my .htaccess file below just in case
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论