質問

I am doing OOP PHP, but without the use of an MVC (which is at the moment too complicated for me to understand, and I don't feel like learning an entire framework). It gets kind of messy on the pages themselves where I need to instantiate objects, a bunch of if-statements and whatnot.

At the moment, I'm just adding a PHP block on top of my HTML and do the most there which can get kind of unorganized too, and also some small PHP blocks in my HTML here and there.

Are there any good and clean conventions when it comes to procedural PHP code in HTML files?

However I am interested in MVC frameworks that are very simple, with only the core functionality. Or barebone MVC framework where I can learn and make it my own. But I have yet to find one.

役に立ちましたか?

解決

The most simple form for you would be to include your class file into your php document to separate it on that level. Then in your php file that needs to utilize the class you would:

require_once('filename.php'); // before you work with the class and usually at the top of the php document.

Then in your php files that deal with the objects you can separate the code somewhat. In principle this is also going to start you down an MVC path, once you master this simple process you will learn more and more.

他のヒント

Why not try out a micro-framework like: http://silex.sensiolabs.org/

If you don't want to go that route I would just use includes, and make sure that you set up your directories correctly. For instance;

site_root/includes/layout/header.php
site_root/includes/layout/footer.php
site_root/includes/functions/whatnots.php
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top