panique / mini2

Just an extremely simple naked PHP application, useful for small projects and quick prototypes.
MIT License
416 stars 102 forks source link

[discussion] How could the architecture of this be improved ? #32

Closed panique closed 9 years ago

panique commented 9 years ago

MINI2 currently consists of 2 simple .php files:

  1. /public/index.php, holding the initialization of Slim and Twig, the configs, the loading of the model and the routes for sure.
  2. MINI/model/model.php, which holds the data handling methods, so it's more or less the model.

MINI2 is just a quick thing I've built for quick projects (in daily agency work you have setup sometimes 3 applications per week), and using real frameworks is totally overdoze in most cases, so this makes sense.

However, it might be better to a.) move the configs b.) split the model to multiple files, so the user can organize data-handling methods (like classic UserModel extends Model, you know what I mean :) ). c.) move the routes, split the routes to multiple files

What do you think ? Ideas ? Code ? Feature branches ?

ghost commented 9 years ago

Interesting stuff this project learning so much.

I have been working on the original PHP-MVC project and plan to commit it but have added theme/cache support for twig which could be useful:

 public function render($view, $data_array = array(), $cache = false) {

        if ($this->enableTwigCache) {
            $cache = true;
        }

        // load Twig template engine
        $twig_loader = new Twig_Loader_Filesystem(SITEFOLDER . 'views');

        //Add path to keep theme seperate from views
        $twig_loader->addPath(THEMEDIR . $this->theme . '/');

        if ($cache) {
            // Cached in APP.cache (needs to be writable by webserver)
            $twig = new Twig_Environment($twig_loader, array(
                'cache' => APP . 'cache',
            ));
        } else {
            $twig = new Twig_Environment($twig_loader);
        }

        //Pass Defaults values to template.
        $defaults = array();
        $defaults['PARENT'] = (string) PARENT;
        echo $twig->render($view . '.twig', array_merge($data_array, $defaults));
    }

2) Moved the Models/Views/Controller into a seperate folder so I can move them about from server to server easily.

3) Used Namespaces/PSR-4 (was orignally just using composer's class loader) to preload any classes I would need through out the project.

panique commented 9 years ago

@djsmithme Sounds good, can you show some code ?

ghost commented 9 years ago

https://github.com/djsmithme/php-mvc-advanced/tree/djs-ideas/djs-ideas

I'll upload it properly when I get a moment.