开发者

Any problem if i will have only index.php instead of

开发者 https://www.devze.com 2023-03-27 16:08 出处:网络
i am trying to create a website, a dynamic one. i wanted to know if is any problem if i will not divide the index.php file, so it will have the header , footer, sidebar etc, in one file. is any thing

i am trying to create a website, a dynamic one. i wanted to know if is any problem if i will not divide the index.php file, so it will have the header , footer, sidebar etc, in one file. is any thing wrong here? So instead having, header.php, index.php, footer.php, sidebar.php, i will create only index.php..

need some suggestions 开发者_如何学Gofrom experts please Thank you for reading this post.


absolutely nothing wrong. well. at the start.

you'll have issues with maintainability of that single file later when it gets bit. if you're planning to grow big.


No there is nothing wrong in that approach, it might be a pain to maintain though.


It's almost always a good idea to split things up this. My typical "simple" site layout has a header, a footer, and a body, each with its own files. It's rare for more than a couple pages to have different headers/footers, so almost every page ends up looking like:

<?php  include('header.inc'); ?>
body goes here
<?php include('footer.inc'); ?>

And the header/footer files boil down to <html><body> and </body></html> respectively (with all the usual css/javascript/meta/headers, etc... of course).

Nothing wrong with keeping everything in a single file, but then you'd have to hard-code your menus/sidebars/footers/headers/etc... into every PHP file.


You need not any additional files.
This files are used only for easy edit, more obvious struct and having main code in different pages


I think it's great. Since your PHP-processor only needs to interpretet 1 file (instead of 4), it'll probably go a lot faster (when you are not using any OP code compiler).


Segregating your code is good practice as it helps prevent duplicate code. Say you want page2.php and you need the same header, footer, sidebar, etc. Are you going to copy/paste in that code? Just make your template views like they're supposed to and piece together your structure for optimal code redundancy avoidance.

If you NEVER plan on scaling this project, one page is fine.


While there is nothing wrong theoretically, this is by definition a bad practice.

By separating functional / organisational wholes into different files / classes / modules, you achieve decoupling and get a larger control level over your application, it will be much easier to maintain, you wont have to harcode and copy/paste much etc...

Why would you want to put all of your code into a single file?

0

精彩评论

暂无评论...
验证码 换一张
取 消