Micro-framework: Slim
Setting up Slim Application
- Create a folder for your project, mine called
slim
- create a
composer.json
in the directory and open up your Command Prompt / Terminal and runcomposer install
. Later you should have something similar to Screenshot #2.Screenshot #1 Screenshot #2
Setting up RedBeanPHP4
- Download RedbeanPHP4
- Create a folder named
RedBeanPHP4
in vendor directory and extract download zip file above and copy therb.php
intoslim/vendor/RedBeanPHP4
– see Screenshot #2. - Include the
rb.php
inslim/vendor/autoloader.php
- Then, add MySQL connection settings.
Let’s start it!
- Create a
index.php
in slim directory and add the following:
Basically what’s in this index.php is to add new user and view a user details.
- You may need to create new database, then new table named users. I used the following fields – id, name, email, created and modified
- Next, when the database and tables created, you may run
http://localhost/slim/users/add/Nasrul Hazim/[email protected]
and you may want to add more records. Suppose each time new user created, you will be redirected to the view user info page –http://localhost/slim/users/view/1
and see the next screenshot – I only var_dump the user details and you want to add some nice view or probably pass a JSON encoding.