Jump to content
MakeWebGames

Modular Layout


Script47

Recommended Posts

By using a clever design pattern. If you harness MVC effectively, you could make an application modular.

Yeah a design pattern is definitely essential.

I think you might possibly be able to utilise a database for this. You'd also need a very could piece of code to search for modules, decompile them if they are in folders or packages and have them implement into your site seemlessly.

With a database you could have a system to turn them on / off, have the url to the package etc.

I don't know if PHP would be the best language for this tbh, it can be done, but how about looking into ASP.NET? You should have more functionality with that, it might make it a little bit easier, even if the only piece of ASP.NET code is to add / remove the modules, or process them.

Link to comment
Share on other sites

Yeah a design pattern is definitely essential.

I think you might possibly be able to utilise a database for this. You'd also need a very could piece of code to search for modules, decompile them if they are in folders or packages and have them implement into your site seemlessly.

With a database you could have a system to turn them on / off, have the url to the package etc.

I don't know if PHP would be the best language for this tbh, it can be done, but how about looking into ASP.NET? You should have more functionality with that, it might make it a little bit easier, even if the only piece of ASP.NET code is to add / remove the modules, or process them.

Why would you need to adopt another language to enable/disable modules? There is plenty of ways/hacks to do it;

  • A database table, like you said.
  • Create a "disabled" file in the module folder
  • Create a "list" of disabled modules in a configuration file
  • Rename the module folder
Link to comment
Share on other sites

Honestly sniko, I was simply doubting the power of PHP for the task, but since I've never tried it I couldn't know for certain. I did say in my post that it could be done in PHP as I was aware of NWE and its modular structure.

Ah well, I think there is enough here to get the OP thinking about his approach to this.

Link to comment
Share on other sites

I developed a PHP Modular MVC Framework, also supports themes so you can have multiple templates.

Released under the MIT license, check: https://github.com/Jo3la/Modular-MVC-Framework

Does not require a database connection to work.

Nice little engine, I have taken a look, do you intend to give any examples on the Database? Do you plan on extending it?

The modular layout is good. Nice simple template system, autoloading, definatly a good start.

Link to comment
Share on other sites

Nice little engine, I have taken a look, do you intend to give any examples on the Database? Do you plan on extending it?

The modular layout is good. Nice simple template system, autoloading, definatly a good start.

Thanks, and yes the database class definitely needs work, currently only supports mysqli.

Examples will come soon, the framework was released just yesterday.

Link to comment
Share on other sites

that would be nice to give people the option to what route they wish to go whether it be mysqli or pdo.

But for the topic at hand I think a good file structure would be your best bet to creating a modular site and enforce the file structure. You don't want a ton of loose files in your directories, not saying you can't have any but those loose files would mainly be for the "core" of your framework.

I know I keep bringing up NWE and may sound like a broken record but I feel its an excellent example of a modular framework so maybe take some notes from that especially since it lets you go many directories deep to grab files for use

Link to comment
Share on other sites

Since MVC has been mentioned I suggest reading this - http://makewebgames.io/showthread.php/43178-MVC-or-not-MVC

I would ask what you want to be modular, and why you are trying to learn about it?

Honestly sniko, I was simply doubting the power of PHP for the task, but since I've never tried it I couldn't know for certain. I did say in my post that it could be done in PHP as I was aware of NWE and its modular structure.

Ah well, I think there is enough here to get the OP thinking about his approach to this.

This confused me a little. Surely you should decide what you want to do then select the best approach for it. Simply wanting something to be modular is hardly a sufficient explanation to say PHP is not the way to go without any context of what the program is going to be.

Link to comment
Share on other sites

This confused me a little. Surely you should decide what you want to do then select the best approach for it. Simply wanting something to be modular is hardly a sufficient explanation to say PHP is not the way to go without any context of what the program is going to be.

Very true, I think I was talking out of my ass that stage.

Link to comment
Share on other sites

  • 2 weeks later...

So I've been messing with some code and think I've got the hang of it. Is it basically like this?

index.php

<?php

include 'links.php';

if(isset($_GET['module'])) {
include 'modules/'.$_GET['module'].'/index.php';
}

 

links.php

<?php

echo '<a href="index.php?module=about">About</a>';

 

modules/about/index.php

<?php

echo 'Some about';

 

That module page even shows up, but it seems too easy to be true. So have I got the basic idea of it or have got it completely wrong?

Link to comment
Share on other sites

So I've been messing with some code and think I've got the hang of it. Is it basically like this?

index.php

<?php

include 'links.php';

if(isset($_GET['module'])) {
   include 'modules/'.$_GET['module'].'/index.php';
}

 

links.php

<?php

echo '<a href="index.php?module=about">About</a>';

 

modules/about/index.php

<?php

echo 'Some about';

 

That module page even shows up, but it seems too easy to be true. So have I got the basic idea of it or have got it completely wrong?

Looks right but I would redirect them to a default page if the module query string isnt there

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...