Slim Framework

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?

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.

1 Like

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?

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.

1 Like

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:

1 Like

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
1 Like

Do i have to install Slim into the folder ā€œappnameā€ or into ā€œappname/www/ā€ ?

same question for ā€œcomposerā€ :smile:

1 Like

I always do it in a libraries/slim directory

1 Like
appname/www/lib/slim

like that?

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

2 Likes

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.

1 Like