Skip to content

flip111/Silex-Redbean-skeleton

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

What is this?

This is a project skeleton that features Silex and RedbeanPHP. It will get you started quickly with building a PHP project. Have a look in composer.json to see which libraries are loaded.

Screenshot of homepage

Installation

  1. Clone the repository or download the zip file and extract it somewhere to disk

  2. Navigate to the directory where the files are with the command line and run

     php -r "readfile('https://getcomposer.org/installer');" | php
     php composer.phar install
     php -S localhost:8080 -t web web/index.php
    
  3. Browse to http://localhost:8080/ and enjoy!

Making your own pages

To get started making your own pages. For example www.domain.com/guestbook you can copy

  • The controller code into the same file or another file in the same directory. Make sure you change $app->match('/' to $app->match('/guestbook'
  • Change the controller name so that silex knows there are different controllers. This will also add a link to your page in the bootstrap navigation bar.
  • The view can be copied to a file in the same directory with a different name. Make sure that in your controller you change the name of the view template here

Expanding functionality

Right now pretty much everything is done in the controller. This is on purpose. When you start out prototyping your project you want to get going fast and see what works. Later when you want to make more reusable components you can start making Form classes or real Model classes. Also take a look at index.php where already quite a few services have been enabled, you can read about them by just googling for them.

Production

Even though this setup is initially geared towards prototyping on your own computer, it doesn't mean you need super heavy frameworks and libraries to be production ready. This setup is actually really fast. There is a section about debugging that you should configure like this

$app['debug'] = false;
R::debug(false);
R::freeze(true);
R::useWriterCache(true);

Twig templates are cached be default. If you need more speed install PHP 7.

Webserver

If you want to use your own webserver you can take a look here and for apache there is a small help section below.

Apache

Look for apache/conf/httpd.conf and inside you should make the necessary configuration. D:/dev/http should be replaced to the web directory in the project.

DocumentRoot "D:/dev/http"
<Directory "D:/dev/http">
    Options Indexes FollowSymLinks
    AllowOverride All
    Require all granted
</Directory>

The AllowOverride All is the important part here. This is needed so that you can get pretty url's like www.domain.com/users/yourname instead of www.domain.com/users.php?user=yourname

Documentation: https://httpd.apache.org/docs/current/howto/htaccess.html

Implementation

Quite a few javascript file have been moved to the header, while it's best practice to put them just before the closing body tag. This is done because the timepicker widget places javascript inline for which some libraries have to be already loaded. I also made a twig extension that collects all the javascript snippets and places them in one block at the end of this page. However since this project is just meant as skeleton i didn't want to add too advanced features.

One other thing is that all the libraries are set at dev-master, for your own project you should stabalize the versions on the ones you like. For now i will try to keep this repo on bleeding edge.

Database

As you might have noticed there is no section so far about any database. The default configuration writes to a sqlite database, which is a high performance database which lacks the more advanced query features. You can keep using this database or read the redbean documentation on how to configure another database.

Redbean configures your database on the fly. This is a huge benefit in development speed, but it also means that you can not use an existing schema. If you need to use existing data then first model the data with redbean on an empty database and then write queries to load your data in the redbean schema.

FAQ

Q: Failed to listen on localhost:8080 (reason: An attempt was made to access a socket in a way forbidden by its access permission) A: Try using another port than 8080

Todo

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published