如何更好地构建文件目录?

时间:2012-07-15 01:22:51

标签: php xml dynamic content-management-system file-structure

我正在研究动态博客/投资组合:

参考链接:http://www.andrewryan.me/

我已经在我的个人网站上工作了一个多月了。我一直在修改东西,因为我觉得我把整个事情弄错了。我知道我在某种程度上,我终于寻求帮助了。

我一直在研究动态网站结构,我想知道一些事情:

  1. 动态内容的最佳做法。

    • 我在根文件夹中有该站点的框架。这包括索引和样式 (以及脚本文件夹,图像文件夹和其他misc文件类型..)

    • 最新的博客条目在索引页面上提取。如果他们想看到我所有的专业帖子/主题,他们只会去任何给定的子部分 (例如:index.php?p = professional)

    • 从那里;如果用户想要完整地查看博客文章,他们只需点击帖子然后进一步动态拉起。
      (例如:index.php?p = professional / thispost(idfk))

  2. 如何在动态内容中创建动态内容。

    • 页面和子页面然后继续在个人文件夹中的链上。 (例如:index.php> index.php?p = personal)
  3. 如何在页面上传到相应文件夹后制作可更新内容。

    • 我应该考虑使用数据库或XML吗?如果是这样,有人能指出我制作此类网站的任何好教程吗?无需对此进行过多解释。
  4. 这是我的文件结构:

    root/   
      > images/  
        ||--> x.png   
      > pages/  
        ||--> personal.php  
        ||--> professional.php  
        ||--> contact.php   
        ||--> 404.php  
        ||--> contact.php 
        > personal/  
            |||--> personalposts.php  
        > professional
            |||--> professionalposts.php  
        > gallery/  
            |||--> galleryposts.php   
      > scripts  
        ||--> scripts.php/js/etc
      |--> .htaccess
      |--> index.php  
      |--> style.css    
      |--> robots.txt  
      |--> humans.txt
    

    ...以及动态网页的代码:

    <?php
        $pages_dir = 'pages'; //Scans the pages directory
    
        if (!empty($_GET['p'])) { //If not empty it will get the file
            $pages = scandir ($pages_dir, 0); //Sets up files as array
            unset ($pages[0], $pages[1]); //Unsets the first two. These are just dots.
            $p = $_GET['p'];
    
            if (in_array($p.'.php',$pages)) {
                include ($pages_dir.'/'.$p.'.php');
            } else {
            include($pages_dir.'/404.php'); //DENIED!
            }
        } else {
            include($pages_dir.'/blog.php'); //if it's the index page
        }
    ?>  
    

    我或多或少想知道我是否正确地使用了结构,或者是否有更好的方法来做到这一点。我希望能够创建一次这个网站,并在需要时自动更新内容。

1 个答案:

答案 0 :(得分:2)

啊,啊哈,我一直在等待的问题。我正在开发一个这样做的网站。 首先,您必须将您的网站分成页面(每个页面都有不同的布局)。例如,要注销,您可以使用以下内容:sitename.com/?action = logout

要回家,你可以去sitename.com,如果你尝试/?p = somethingThatDoesntExist然后你仍然可以访问主页(或错误页面)

如果您可以访问网络根目录下的内容,那就更好了。然后,您应该将所有.php文件保存在/ root / content /中,并且只保留/ root / www /

中的一个index.php

此代码是我用来向玩家提供登录页面的代码(如果他是管理员,则可选择)

// Check if alternate page requested
if (!empty($_GET["p"]) and !empty($_SESSION['id']))
{
    $page = $_GET["p"];

    if (!empty($pages[$page]))
    {
        $page_array = $pages[$page];
        if ( (!empty($page_array['auth'])) && ($user['Auth'] < $page_array['auth']) )
        {
            $page_array = $pages['index'];
        }
    }
    else
    {
        $page = '';
    }
}

然后,你做了基本的事情:

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang='en'>  
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />  
        <title><? echo $page_array['title'] ?></title>

        <link rel="stylesheet" href="css/3p/reset.css" type="text/css"/>
        <link rel="stylesheet" href="css/3p/formalize.css" type="text/css"/>

        <link href="css/bootstrap.css" rel="stylesheet">
        <link href="css/main.css" rel="stylesheet">
        <link href="css/bootstrap-responsive.css" rel="stylesheet">
    </head>  
    <body>  
            <?php
                    require("../content/header.php");
                    require($page_array['require']);
                    require("../content/footer.php");
            ?>
    </body>
</html>

以下是page_array的内容:

$pages = Array();
$pages['admin'] = Array(
    'auth' => 3,
    'require' => "../admin/index.php",
    'title' => "Administration - NPG CP"
);

$pages['index'] = Array(

    'require' => "../content/index.php",
    'title' => "Home - NPG CP"
);

$pages['friends'] = Array(

    'require' => "../content/index.php",
    'title' => "Friends - NPG CP"
);

$pages['pm'] = Array(

    'require' => "../content/index.php",
    'title' => "Messages - NPG CP"
);

$pages['stats'] = Array(

    'require' => "../content/index.php",
    'title' => "Statistics - NPG CP"
);

在我的网站上,我只使用一个处理其他所有内容的可查看文件。我希望我帮助过你。我可以给你的网站提供源代码,只需发送电子邮件给我[my_username] @ gmail.com吧:)

相关问题