douqiao5543 2011-07-06 17:12
浏览 34
已采纳

需要php模板帮助和清理网址帮助

I'm new to PHP and web development in general, but have been a programmer for 5 years. I'm trying to work on my own website from scratch using Notepad to edit my PHP files and WAMP for my server. I'm able to view my files fine in Safari, Chrome and Firefox, but not IE (which we all know IE isn't the greatest) because I'm using some HTML5 stuff. Anyways, I have an Includes folder that holds my files for my header, menu and footer. I have an index.php file that includes these files and displays them fine. In the center of the page is where I want the content. To try and keep clean urls, I made quite a few folders and put this same index.php file in there (e.g. Profile/index.php, Forums/index.php, etc.). I did this so when I went to localhost/mysite/profile/ it showed me the template I wanted to use. However, there has got to be a better way to use the template and a better way to have clean urls. I'm not currently hosting this site anywhere so I don't know if I'll have access to the htaccess file (not even sure what it is honestly, just seen it mentioned), but I was curious of having the folder structure (one folder for each menu item) is a normal or ok practice? I was also curious if there is a way to use the index.php without having to copy and paste it every time I make a small change. Any help would be appreciated. Thanks.

  • 写回答

3条回答 默认 最新

  • dounang1974 2011-07-06 17:15
    关注

    Copying the index.php file is not really the way I would go. It seems messy and there are a few other options. If you want the urls to be clean and search engine friendly you should really have a look at url rewriting using .htaccess

    You're saying that you're not sure if you will have a server with "access to the htaccess file" but if you can upload files you can always upload a .htaccess file as well -- the problem is that the web server is not always using them or might not have mod_rewrite enabled. In this case you can get your urls on the format of http://www.example.com/index.php?u=/Profile/foo (this is also my preferred way to handle url rewrites).

    In your index.php just make sure to read the requested url parameter passed by mod_rewrite and include whatever files in the folder that you need. Actually, you don't even need a "physical" folder structure, you might want to implement it using classes or something like that. (I'm sure I would).

    I would really recommend that you go have a look at a good PHP framework, CodeIgniter for example. Even if you decide to code everything from scratch, you would still learn a lot about best practices for url handling, databases, the MVC pattern, template engines, database abstraction layers and PHP coding in general.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?