Slim Framework


#1

Hey guys,

has anyone implemented the slim framework into his app?

It looks really easy but i want to know, if there are some tricky steps :smile:
Did you use an tutorial for that?


#2

Slim is a nice framework though I prefer Silex or Phalcon. Slim is fast, but it lacks a proper documentation (It is not friendly to novice PHP developers).

On the other hand, Silex has an excellent documentation plus more than enough online examples.
For example, this is my blog post on topic of Silex: http://www.gajotres.net/best-available-php-restful-micro-frameworks/7/

But go ahead if you want to use Slim, you won’t regret it.

P.S. I have an experience with Slim, Silex and BulletPHP. I successfully used them with Ionic and OnsenUI.


#3

Okay, great! Thanks for your advice.
First of all i will use slim, but silex is also interesting.
I just use it for 6-8 little operations.

Okay, if there isn’t any tricky thing i try to install it :smile:

Is it right, that i could install it via composer but also manuall or is it a step-by-step installation: first install composer, than manuall?
http://docs.slimframework.com/start/get-started/

How do i integrate it, do you got an tutorial?


#4

Best and most common way is via Composer, because this way you’ll get all other dependencies (I can’t remember if there are any). Everything else is a piece of cake, you only need these two lines to start your project:

require "vendor/autoload.php";
$app = new \Slim\Slim();

Just be careful if you’re going to use an ORM. I had few problems mixing Propel with Slim/Silex.


#5

How looks the directory strucuture with Slim?

Sorry for all my question, I’m really new with this things :smile: But i love every minute working with Ionic/Angular :smile:


#6

I’m currently working so I can’t access my private repository but it looks something like this:

framework/
    libraries/
        autoload/
            autoload.class.php
            resource.namespaces.php

        router/
            tests/
                router.test.php
            router.class.php
            resource.routes.php

    configuration/
        framework.configuration.php
        router.configuration.php

    controllers/
        index.controller.php

    models/
        index.model.php

    views/
        default/
            index/
                index.view.php
            header.view.php
            footer.view.php

    assets/
        css/
        javascript/
        images/

    index.php

#7

Do i have to install Slim into the folder “appname” or into “appname/www/” ?

same question for “composer” :smile:


#8

I always do it in a libraries/slim directory


#9
appname/www/lib/slim

like that?


#10

It really depends on how complex you need to make it and how you plan to maintain the code afterwards. I just stuck my 30+ services into index.php and since I’m very adept at SQL, I see no reason nor value in using ORM. But do take care in vetting SQL parameters, do use https and do use or device some auth scheme to keep the small-time crackers off your services.

Build a simple example first with say POST and GET - just to see that it all works - and then take a pencil and paper to map out your services such that they can easily be used with Angular’s $resource - that should save you tons of work.

Here is one of the many links exemplifying slim: http://www.blog.iamaronbarbosa.com/building-a-basic-crud-application-using-angularjs-and-slim-php-framework-part-1/

Note that function declarations can be simplified into sumtin like:

$app->get(’/token/:old_token’, function ($old_token) { … code …});

Familiar to Javascript developers but maybe strange if you’re a PHP person.

Cheers


#11

You can use any dir structure you want.

I managed to dig my last Silex project, basically I left silex in a Composer prebuilt dir:

project_folder/vendor/silex

with other dependencies.

A reason for this is, there’s no such thing as a correct project structure. Every person, team, company will have it unique solution. You should follow only one rule, it must be readable.