51

How does anybody learn how to use this system?

I can't seem to find any tutorials or books or anything on how to use this program. Yes their website briefly explains a few things but there is no clarification or anything. Google has failed me.

Can anyone help me with this? I need to use this but it looks completely foreign to me.

Steve Whitmore
  • 903
  • 1
  • 9
  • 22

6 Answers6

95

UPDATE: After 3 years, It is time to add some updates to this answer. A lot has changed in slim framework (and even PHP) during this time.

Slim version 3 has been released and brought some major changes to it. In my tests, It is slightly slower and tad more complicated than slim 2, But architecture wise, it is much better, secure, suited for both large projects and small website alike.
Also, PHP has adopted really good standardization in form of PSR which I think everyone should start to adopt. Object-oriented implementation is improved a lot in 3 years and with the release of PHP 7, I don't miss my Java days anymore.

Some links to getting started.

Treehouse and few others have made some tutorials on Slim 2 as mentioned in comments, they are worth looking. Slim 3 is yet to have a beginner's tutorial videos but framework in itself is simple to understand. For simple websites, I would still recommend Slim 2 for those not really an experienced programmer. But if someone is trying to build a big professional application/product, Use Slim 3.


older answer

I will agree that slim lacks certain attentions in terms of documentation and guides. There is still no great tutorial for it, but if you have good pickup skills, Let me point you to the only worthwhile thing I found on net.

This is Presentation on the slim framework. Not a complete tutorials but it does explain certain basics to use the framework. It has helped me when I first picked up the framework. It is a Presentation By Jeremy Kendall.

The Slides can be found on slideshare.

The video is 43 min long but it is worth.

Abhinav Kulshreshtha
  • 2,147
  • 1
  • 23
  • 38
  • I suffered same problems as yours for months before this conference. No guide, no tutorial. Its good i could help you. Happy RESTing your websites. Mark this as your answer if it helped. :-) – Abhinav Kulshreshtha Feb 26 '13 at 13:08
  • Those slides were very useful to me. – Nic Nov 03 '13 at 17:47
  • Nice to hear that it was helpful. I now have some experience using this framework. I will be uploading my own Slides on the updated version after the workshop I would be conducting in a local college next week. I am hoping it would be helpful also. – Abhinav Kulshreshtha Nov 20 '13 at 10:31
  • Check this tutorial!!! http://coenraets.org/blog/2011/12/restful-services-with-jquery-php-and-the-slim-framework/ – James111 Jul 20 '15 at 12:11
  • 1
    Wow, Still active. well in two years, slim has really gained some momentum. I am eagerly waiting for slim 3. There is a very good video tutorial from [TeamTreeHouse](http://teamtreehouse.com/library/building-websites-with-php) You would learn practical usage. But I would Recommend you to read [this artical](http://www.sitepoint.com/best-practices-rest-api-scratch-introduction/) . Its just great . – Abhinav Kulshreshtha Jul 20 '15 at 12:19
  • @James111 The link you gave was one of the first actual tutorial on the net, But now it is way to outdated (year 2011 and slim 1.x I think) , some parts of code are now deprecated. – Abhinav Kulshreshtha Jul 20 '15 at 12:26
  • @AbhinavKulshreshtha thanks I'll check it out! I'm just getting into slim and I'm excited to start learning more and more of it :) – James111 Jul 20 '15 at 12:27
  • Do you use named functions or anonymous functions? I'm currently learning slim in my course and the teacher prefers using named functions and putting all the requests at the top of the page! Is he correct in doing that? – James111 Jul 20 '15 at 22:51
  • 1
    for simple things like redirecting, simple showing data etc, Anonymous functions. For something complex which might need re-factoring or maintenance in future, multiple error checking, complex data handling etc, I prefer to use named function to simplify the maintenance . But I dont keep these functions in classes, I tried it before it is much a hassle. instead I might use objects of other classes in the definition to simplify the code. – Abhinav Kulshreshtha Jul 21 '15 at 10:04
  • @James111 and Sarwic I have updated the answer with much more recent links, if you are interested. – Abhinav Kulshreshtha Feb 03 '16 at 19:15
24

This is how I did it.

I read few tutorials from people up there then I "walked" through code. Slim is really "slim", only ~50 files.

Check Slim.php file, everything starts there. See what's going on in the constructor, then see get/post methods. If you have xdebug installed then it could help you walk through one simple request and so on.

And as an added bonus you will learn a lot about PHP, patterns, basically how everything works.

P.S. My first answer here :)

Kamran Ahmed
  • 7,661
  • 4
  • 30
  • 55
DinkoM
  • 371
  • 2
  • 8
13

Key point from the presentation mentioned above by Jeremy Kendall (do watch it), that the docs don't mention until 2/3rds of the way down: to let Slim handle the routing, you need an .htaccess file:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]

Et voila, the example at the start of the Slim docs will now work for you. smacks forehead

More info on the syntax and content of these .htaccess rules:

stilkin
  • 139
  • 1
  • 5
Renee
  • 292
  • 2
  • 9
  • 1
    Another tip, remember do allow htaccess on apache: DocumentRoot /var/www/slim ServerName slim.local Header add Access-Control-Allow-Origin "*" AllowOverride all – Bruno Soares Sep 22 '14 at 15:22
5

Simple Example

Neeeded 3 files

  • file to program(eg- index.php/myfile.php)
  • Slim(downloaded package)
  • .htaccess

Step 1: .htaccess file

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f

RewriteRule ^(.*)$ index.php [QSA,L]

Step 2: myfile.php

require 'Slim/Slim.php';

\Slim\Slim::registerAutoloader();

$app=new \Slim\Slim();

$app->get('/',function() {

    echo "Hello World";

});
$app->run();

Running Program

localhost/project1/myfile.php

More tutorials

http://nesbot.com/2012/6/26/multilingual-site-using-slim

https://github.com/briannesbitt/Slim-ContextSensitiveLoginLogout

Misha Zaslavsky
  • 8,414
  • 11
  • 70
  • 116
Akshaya Moorthy
  • 309
  • 3
  • 11
3

The following posts helped me a lot in getting me started with my first slim application. But they are very specific to building RESTful web services.

ericbrandel.com

androidhive.info

coenraets.org

I went through the posts and then downloaded the code to play with them. Later I was able to mix and match the best pieces and start my development in under 2 days time.

Ananda
  • 888
  • 9
  • 19