Slim Framework 101

Hi there, folks!

My name is Revzan. I am new with Slim. I have couple of questions and i’ll be glad for good answers you gave.

  • I am currently working on a GOOD directory structure for my application. Any rules maybe?
  • I am going to use view template for slim and wil be mixed with angular.js. will it be okay?
  • the last one. i really need to know how slim does the subviews

Thanks,

  1. I have settled on this directory structure and am very happy with it:

    ./config
    ./config/dependencies.php
    ./config/middleware.php
    ./config/routes.php
    ./config/settings.php
    ./sql
    ./src
    ./src/bootstrap.php
    ./src/Controller
    ./src/Helper
    ./src/Middleware
    ./src/Model
    ./src/TwigExtension
    ./src/Util
    ./templates
    ./var
    ./var/cache
    ./var/cache/twig
    ./var/log
    ./vendor
    ./web
    ./web/css
    ./web/css/img
    ./web/fonts
    ./web/img
    ./web/js

  2. I’ve never used Angular but I see no reason why this should cause problems

  3. Not quite sure what you mean by “subviews”

Hope this helps.

2 Likes

Thanks man! This is inspiring.

  1. templating, i guess. like extending the other views, calling content, etc.

Here’s a sample call to return a rendered Twig template from your controller:

return $this->view->render ($response, 'myTemplate.twig', 
                            ['param1'=>$value1, 'param2'=>value2]);

The Controller constructor looks like this:

public function __construct (\Interop\Container\ContainerInterface $container)
{
    $this->auth          = $container->get ('auth');
    $this->flashMessages = $container->get ('flash');
    $this->hash          = $container->get ('hash');
    $this->logger        = $container->get ('logger');
    $this->router        = $container->get ('router');
    $this->settings      = $container->get ('settings');
    $this->session       = $container->get ('session');
    $this->view          = $container->get ('view');

    $this->jsonRender  = new JsonRenderer();
    $this->jsonRequest = new JsonRequest();
}

Hope this helps.

1 Like