Yeah, I know… there is already too many PHP frameworks out there, why would I want to build another one?! I turns out that I am very picky in the way I write code and there is always something bothering me in a certain framework. Usually, when you start using a new framework, there is a tone of documentation and best practices to go through before you can really start to take advantage of it. And I think, we all have heard some jokes on a topic of misusing the frameworks. I didn’t want to have any of that problems, so I took a day and write my own.
One can never misuse a framework that he wrote himself.
Bottle is lightweight, it is simple and it is salable. There is no documentation to go through, there is just
readme.md document. All that this framework does, is that it brings together Twig template system and AltoRouter
outing system, which is probably all that you are going to need 90% of a time. The goal is to provide a system of
writing a code that can be easily expanded by the developer in any way the wants. A strong inspiration for this
framework was Python’s microframework called Flask. You’ve probably heard about all of the technologies I mentioned,
but if you didn’t, you can read more about them on the links below.
General project structure is briefly described below but there is nothing keeping you from expending that structure to your own needs. Note: all Page class files (which have extension .class.php) in folder
pages/ are automatically included.
core/ (framework files which generaly should not be modified) pages/ (php files for logic of different pages) public/ (public filder which displays the page to the user) index.php static/ (folder with static files like css, js or images) templates/ (folder which cointains all Twig templates) main.php (main application file where we define all application settings and routes)
Getting started with Bottle framework is very easy. You just need to clone the repo and call
composer install in the project root directory. You can read more about composer here: https://getcomposer.org/. Of course I assume that you have Apache already installed. I have done my best to document the code and provide some examples in the project skeleton.
cd /var/www/html/ git clone https://gitlab.com/ja4nm/bottle.git cd bottle/ composer install # modify setting in main.php # navigate to http://localhost/bottle/public/
You can also configure apache to point directly to the
public/ directory. Then you will be able to access the page through url http://localhost/.
1) Modify file
/etc/apache2/sites-available/000-default.conf to look like this:
<VirtualHost *:80> ServerAdmin webmaster@localhost DocumentRoot /var/www/html/bottle/public/ <Directory /var/www/html/> Options Indexes FollowSymLinks AllowOverride All Require all granted </Directory> </VirtualHost>
2) Restart Apache using command
sudo /etc/init.d/apache2 restart
$settings->base = "/" in file
main.php in project root directory.