What is Barebone MVC (BBMVC)?

It is a very simple framework which enables clear, rapid and secure development of PHP applications.
It is modular, object oriented and uses Smarty as a template system.

Long story short: all parameters will be automatically checked for security. The required modules, functions and templates will be automatically called and loaded.

How BBMVC works?

Basically, I want every single webpage to be called via index.php, so that I (and you) can have a better control of everything.
For this, I suggest the following URL "format": http://domain.com/index.php?module=CdCollection&action=cdEdit&cd_id=3&other_param=1
Mark the module and action parameters, BBMVC will be looking for these.

First, let's talk about the module.
One module consists of 4 components:

The security and SEO part are not mandatory.

Every class.ClassName.php file should hold the ClassName class.

The dispatcher(BBMVC) checks for the existence of the above mentioned folders, files and classes.

The CdCollection class should have a public method called cdEdit.

[Security checks are done, see below]

If no error occurs, then the CdCollection->cdEdit() method is called and the /templates/CdCollection/cdEdit.tpl template is displayed.

Security checks

BBMVC provides you a way to automatically check all _GET, _POST and _COOKIE parameters. You can enable/disable security checks using the _SECURITY_ENFORCE constants defined in the configuration file.

In order to check the above cd_id parameter, you must have a public function called check_GET_cd_id in the CdCollectionSecurity class. Same for other_param, you need a function called check_GET_other_param.

To check a _POST parameter, you will need a check_POST_paramName function.

Template special functions

In order to be more flexible and allow easy integration of the SEO part, bbmvc has a smarty block function called a which should be used everywhere you have links. Eg:
Instead of inserting a link like <a href="index.php?module=CdCollection&action=cdEdit&cd_id=5">...</a>
the url function should be used like this:
{a module=CdCollection action=cdEdit cd_id=5}...{/a}

If you have a form, then you should use the similar url smarty function, like this: <form action="{url module=CdCollection action=cdUpdate}" method="post">

Some other things about the a/url smarty functions:

SEO component

Barebone MVC can help you build search engine friendly URLs very easy.
The first step is to use the above mentiond a/url smarty functions. Let's take this as an example:
{a module=CdCollection action=cdEdit cd_id=5}Abc def{/a}
The resulting link will look like <a href="http://www.domain.com/index.php?module=CdCollection&action=cdEdit&cdId=5">Abc def</a>
but we want something like this:
<a href="http://www.domain.com/abc-def.html">Abc def</a>

Now the second step comes. You need to create the /modules/CdCollection/class.CdCollectionSeo.php file containing the CdCollectionSeo class. The CdCollectionSeo needs to have a public function called seo_cdEdit. This seo_cdEdit has an array as a parameter. For the given example, the array looks like this:
array("module" => "CdCollection", "action" => "cdEdit", "cdId" => "5");
Basically, you have all the parameters passed to the a/url smarty function. Now it's a matter of choice on how you handle the parameters and how you return the string used in the SEF URLs.

Very important: you will have SEF URLs only if you set _USE_SEO_LINK to 1 in your config/profile file.

I will add more suggestions here, for optimizing this process. Also, I will add info about the server side settings(apache, mod-rewrite) needed for the URLs to work.

Download

bbmvc-0.2.0.zip

Example

A small example build on BBMVC: http://example.bbmvc.org
The example is included in the download.
Take a look at the sourcecode and see how everything is nice and clear. (See /modules and /templates folders)

Installation

Requires PHP 5.x, MySQL and the mysqli PHP extension.
BBMVC is in no way dependent of MySQL, only the bundled example is.

Unzip bbmvc-0.2.0.zip in your web-development folder.
Create a database and create the table found at /path-to-bbmvc/sql/tables/cds.sql.
Edit /path-to-bbmvc/config/config.php and set the following constants: _URL_MAIN, _DIR_PROJECT, _DB_USER, _DB_PASS, _DB_HOST, _DB_NAME.
Make the /path-to-bbmvc/tmp folder writable by your webserver.
Open your webbrowser at _URL_MAIN

Feedback

Please send me feedback to feedback.
This is my first open-source project. I know there are a lot of things missing (docs, svn, bugtracking, etc) but they will come. Rest assure.
"Release early, release often".

Authors

Mihai Brehar - main developer

Ovidiu Farauanu