网站结构 [英] Website Structure

查看:27
本文介绍了网站结构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对 php 很陌生,我正在尝试确定组织页面的最佳方式,并使用 PHP 交付它们.我的两个(基本)想法是:

I'm pretty new to php and i'm trying to decide the best way to organize the pages and, using PHP, deliver them. The two (basic) ideas I've had are:

  • 一堆带有 PHP 的单独页面,包括页眉、页脚和菜单.

  • A bunch of individual pages all with PHP includes to have the header, footer, and menu.

具有菜单、页眉和页脚以及主要内容的包含的单个主页.页面名称来自 URL 中的一个变量.

A single main page that has the menu, header, and footer, along with an include for the main content. The page name comes from a variable in the URL.

有没有人有其他建议或想法?这是非常基本的东西,但我想我会看看是否有人有更好的想法.

Does anyone have any other suggestions or ideas? This is pretty basic stuff, but figured I'd see if anyone has any better ideas.

谢谢

推荐答案

我以前在两个方向都做过,虽然它们都有优点和缺点,但我倾向于您的第二个选项,即包含布局的单个主页.这类似于母版页在桌面发布应用程序中的工作方式,ASP.NET 很好地实现了这个想法 - 我并不是说您应该切换技术.

I've gone in both directions before, and though they both have pros and cons I lean toward your second option, the single main page that contains the layout. This is similar to how master pages work in desktop publishing applications, and ASP.NET has a nice implementation of this idea - not that I'm saying you should switch technologies.

但是,如果您确实走这条路,请使用 mod_rewrite 将您的路径导入 PHP 母版页,而不是 URL 中的查询字符串.您的 .htaccess 文件应包含以下内容:

However, if you do go this route, use mod_rewrite to get your paths into the PHP master page, rather than querystrings in your URLs. Your .htaccess file should contain something like:

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [S=1]
RewriteRule ^(.*)$ /index.php?path=$1 [QSA]

这基本上是说如果他们要求的文件不存在,而不是将 404 错误处理移交给 index.php,并使用查询字符串变量中的 URL 路径.所以 "http://example.com/path/to/page" 最终达到索引$_GET['path'] 设置为/path/to/page"的 .php.从那里您可以从数据库、平面文件或您拥有的任何内容中提取内容.您还可以根据请求的路径选择不同的模板.

This basically says if the file they ask for didn't exist, instead of giving a 404 error hand off processing to index.php with the URL path in a querystring variable. So "http://example.com/path/to/page" ends up hitting index.php with $_GET['path'] set to "/path/to/page". From there you can pull content from a database, a flat file, or what have you. You can also choose different templates based on the path requested.

这篇关于网站结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆