Slim - thoughts and conclusion

TL;DR I gave up

On my way searching for a PHP Backend which does only regular RESTful CRUD with a Login/Logut Auth as addon, I started with Laravel and at least got it worked until the authentication stuff cames up to do.
But it was not possible for me after 2 whole weeks of struggle&research to get it done with this god damn airlock/sanctum beast.

So I left that PHP Monster Laravel in searching on again for a lightweighted, more ‘simple’ structured PHP backend framework.
At first sight, I thought I found it with Slim… but wide of the mark!

Slim4 is really more complicated, more murky than everything else I saw before.

Yeah, great: there are skeletons. Bt in the end, they really didn’t helped me out to reach my aim.

The big, fullstacked one (“odan/slim4-skeleton”) was impossible to understand and unable to strip it down being a simple RESTFul Backend, with Login/Logout Auth and session stuff (CSRF or same site cookies)…
and two others, more tiny skeletons (slim/slim-skeleton and odan/slim4-tutorial )
were too different to understand why they are different and I even was not able finally to get a least one simple GET request running to fetch a real “SQL select” from my existing databases.

Only thinking about how much efforts I had to spend at the very begining to get it run with apache’s server and even Cors was an obstacle because it was just done very hidden in the “slim/slim-skeleton” and led to misunderstandings.

Unfortunately the “slim/slim-skeleton” has no documentation in how to amplify it with auth and a real, just existing MySql database.

And the stuff from odan has plenty of documentations.
Very well, but it doesn’t help a newbie to get success.
It seems to be, that it needs month of trainings and exercises first, only in getting you something like i.e. “dependencies injection container” in your mind, not to mention all the other stuff. Hell!

So you may ask now, what a moron is writing here?!
I worked for many yrs as a professional C++ developer and since 2009 I began developing many Intranet frontend projects with ExtJS.
But Sencha has buried itself some yrs ago now and I started with Vue and made successful, pretty frontends with the help of Quasar, Axios, Vuex and all the other great helpers out there.

Really, these frameworks were all pretty much easier understandable than those PHP Backend monsters!

Sure, I must confess, that my PHP knowledge is obviously somewhat of PHP4, but I thought many concepts I know of ES6 and further would help me out… again, wide of the mark!
Although I even managed Eloquent ORM in Laravel!!!

Of course: Node, Express, Knex, Objection, Paseto Auth, and so on, aren’t easy aswell, but at least:
It’s ES6 :wink:
But I have no choice to use it in production environment (only PHP available).

I think, there are many frontend fellows out there, who just got ready frontends in the javascript world and are looking for an easy way to get its data from a PHP RESTFull backend with an secure authentication - and nothing self-tinkered.

So it would be great, maybe to provide such a slim4-skeleton. It should ends up in doing all the GETs, PUTs, POSTs, DELETES, Auth at the postman’s interface.
Maybe it would bring slim to an wider audience, than having perceived only one expert here: odan
Just my 2ct.

Hi @DonSherman

Thank you so much for your valuable feedback.

Please keep in mind that all the mentioned requirements, concepts, technologies are not trivial. You can’t learn, understand and implement all this in 2 days or 2 weeks. Building up this knowledge and experience usually takes several years or even decades regardless of which programming language or framework you use.

I wrote a tutorial especially for Slim which explains all these modern aspects (like DI container) in a short and concise way. The tutorial also explains with many examples how to create a small Slim application with database accesses. All other features can be added individually on this basis.

Frameworks like Laravel take many decisions from you. With Slim, you have to or are allowed to decide yourself. I think that this freedom and flexibility is just the strength. If you are looking for a ready-to-use solution, you are better off with Laravel or Symfony.

Also in the frontend area the complexity has increased enormously over the years and some “JavaScript monsters” have emerged. The demands on us web developers have increased in all areas, especially in architecture, scalability, testability and of course security. All this has the consequence that more and more concepts have to be learned and implemented. The times are long gone when we upload simple PHP files to the server, and we are done. Technically, of course, this is still possible today, but you will regret this way very quickly.

Slim is a micro-framework, is like a thin picture frame, and you can draw the picture inside as you like. With other big frameworks is like painting by numbers. There is certainly something for everyone. However, it is important to have a solid and good understanding of all the modern basics of this technology.


Quotation from: Slim 4 Documentation - Slim Framework

What’s the point?
Slim is an ideal tool to create APIs that consume, repurpose, or publish data. Slim is also a great tool for rapid prototyping. Heck, you can even build full-featured web applications with user interfaces. More importantly, Slim is super fast and has very little code. In fact, you can read and understand its source code in only an afternoon!

an afternoon!?!?
Seems to be a joke, or I was so ignorant and didn’t know, that an afternoon could take months or even yrs :wink:

Indeed, this sentence was unfortunately misleading and has been removed.

removing something isn’t always the best way.
I would had added a sentence and explaint, why it could also take a long period of time in understanding and successful using this tool.
But as I wrote in a PM here to someone who had proposed me Aphiria as framework:

…Meanwhile I went back to laravel giving it a last chance - with success now.
I managed auth w/o the use of airlock/sanctum. But I must admit, that I don’t understand plenty of things there how laravel works - no good start regarding security issues…

But a remarkable thought in Aphira’s instruction list is this:

…we looked at frameworks, and usually found at least one major problem with them all:

  • Generally too much magic going on behind the scenes

So in the end my personal conclusion now, working for 30yrs as a professional SW developer:
the only thing that really matters is having a huge community.

If a tool/framework does have it, implies, that it has just grown enough and beeing kind of matured, that at least “one of a thousand” would yet have had ‘your’ problem and posted it.

So ‘stackoverflow’ is your friend and an answer to the issue will not take too long - even if it might be only a ‘messy’ workaround due to the framework’s lack about having a good, more slim or better conceptually approach.

Why are there so many frameworks out there? Even in the same language (php)?
Why does so many (good) devs think, that they are so genius and have in mind to make it better, than all competitors?
The key to a best solution would be rather in working together for one tool, instead of creating everytime a new one.
Of course: this is only from a customers proint of view - and mainly only customes pays your salary.

Sorry for so much text.
But I made exactly the same experciences in the Javascript Frontend world some time ago.

I’m glad you found a solution that works for you. The documentation is still being improved. Of course it also needed the feedback of the community and people like you to get better.

I didn’t know Aphira before and that’s why I took a quick look at it. My first impression is that it requires even more know-how and background knowledge than Slim. Example. I also don’t like to wire all dependencies manually, I prefer autowiring. Also, Aphira does not use PSR interfaces. That alone would be a reason for me not to use Aphira.

Generally too much magic going on behind the scenes

I think that Slim does exactly what a framework should do: routing and dispatching. The DI container is optional. If this is still too much or magic for you, you can take a look at nikic/FastRoute.

Compared to Laravel and Symfony, the Slim community is actually very small. The support from the large communities is very important, especially for beginners. But you also have to differentiate between the different types of frameworks and the ecosystems based on them. Laravel and Symfony belong to the general-purpose frameworks and Slim is a micro-framework. A general-purpose framework can integrate other plugins or bundles based on a fixed structure. In Slim, however, such an ecosystem cannot emerge because this “plugin mechanism” is missing. In Slim however each individual component can be integrated with the help of “Composer” and some container definitions. This is more complex, but also more independent and flexible.

Why are there so many frameworks out there? Even in the same language (php)?

I don’t see it that way. In recent years, the number of actively maintained PHP frameworks has been reduced enormously to a very few such as Symfony, Laravel (based on Symfony), CakePHP, Laminas and Slim.

Why does so many (good) devs think, that they are so genius and have in mind to make it better, than all competitors?

Because they can :wink: Joke aside, this is not a problem of the PHP community. Maybe you confuse PHP with JavaScript. The PHP-FIG is a group of experts trying to find ways for us to work better together. For this reason, this group has also developed various specifications for frameworks such as PSR-7, PSR-15 etc. Unfortunately, the big frameworks like Laravel and Symfony are not yet ready to implement these standards, probably to strengthen their own ecosystem (a.k.a. vendor lock-in).

Conclusion: Slim is simple but not easy. Slim cannot be learned in an afternoon. Also PHP and development in general cannot be learn in an afternoon. Everything is relative, even complexity. Everything in life has its advantages and disadvantages. We have to find the right balance. Everyone must decide for themselves what suits them better and what does not. Luckily, we have the freedom to decide this for ourselves.

Kind regards