MuscaKit is an Open Source MVC framework and Content Management System. It was created in 2012 in an interactive agancy in Barcelona and was intended for rapid development of small to medium-size websites and any kind of internet application.
Demo application is avaliable here.
Administration panel is here.
Login using username: demo and password: demo
- PHP >= 5.3
- Apache with mod_rewrite enabled (or equivalent)
- MySQL database
- Download files from github
- Create a MySQL database and import SQL file that you will find in downloaded files in
protected/muscakit.sql
- Set up access to the database in two configuration files:
protected/config.php
andadmin/protected/config.php
Done! Now open a web browser and go to a directory where index.php
is located and you should see a "Hello world" page.
You can access administration panel at URL your_app_url/admin
using username: demo and password: demo
To change username and password click "Hello demo" link in the top right corner in administration panel.
There are 2 basic ways how you can structure your application: Standard MVC Structure and Modularized Structure
In Standard MVC Structure files are organized in three basic folders, one folder for each of MVC layer. We have a folder with Controllers, a folder with Models and a folder with Templates:
protected
----Controllers
--------IndexController.php
--------NewsController.php
----Models
--------ProductModel.php
--------NewsModel.php
----templates
--------layout.tpl
--------home.tpl
--------contact.tpl
This approach is preferable for smaller applications, when there are only a few controllers. However, it is not scalable. When you start adding additional functionality to the app this kind of file structure becomes inconvinient to maintain. Once you have more than 10 controllers it becomes more difficult to find a specific file. In that case it is better to use Modularized Structure
In Modularized Structure 1 the Modules
folder will contain modules - the actual parts of your application. You can think of modules as mini applications. Each module has it’s own folder that contain it’s controllers, models and templates. If the module has multiple templates, files can be further distributed into Controllers
, Models
and templates
subfolders.
protected
----Modules
--------Home
------------HomeController.php
------------home.tpl
--------News
------------Controllers
----------------NewsController.php
------------Models
----------------NewsModel.php
----------------TagsModel.php
------------templates
----------------list.tpl
----------------details.tpl
Standard MVC and Modularized Structure can coexist and you can use both at the same time.
All page requests are processed by the Front Controller file index.php
that is located in the root folder.
MuscaKit offers automatic routing. This means that the router is trying to find a controller and action matching the given URL.
Following routes are possible:
http://domain.com >> \Controllers\IndexController->index()
http://domain.com/product >> \Controllers\ProductController->index()
http://domain.com/product/all >> \Controllers\ProductController->all()
http://domain.com/product/details/123 >> \Controllers\ProductController->details(123)
http://domain.com/shop/product/details/123 >> \Modules\Shop\ProductController->details(123)
Default controller name is IndexController
and default action name is index()
.
If controller name or action name consist of multiple words they can be separated in URL by character -
or _
or glued:
http://domain.com/myproducts/showlatest >> \Controllers\MyProductsController->showLatest()
http://domain.com/my-products/show-latest >> \Controllers\MyProductsController->showLatest()
http://domain.com/my_products/show_latest >> \Controllers\MyProductsController->showLatest()
Controllers are located in protected/Controllers
folder and are autoloaded by Composer. Controller class name should finish with word Controller
, eg.: ProductController
.
The class should extend \MuscaKit\Controller
class.
Public controllers' methods can be called by the router we will refer to them as actions.
Models are located in protected/Models
folder and are autoloaded by Composer.
Templates are located in protected/templates
folder.
Smarty Template Engine is used for writing templates.
Smarty object can be accessed inside a controller by template
property:
$this->template->assign('param', $param);
$this->template->display('home.tpl');
A template can extend layout file, for example:
home.tpl
{extends file="layout.tpl"}
{block name=content}
Hello World!
{/block}
layout.tpl
<html>
<head>
{block name=css}{/block}
</head>
<body>
{block name=content}{/block}
{block name=javascript}{/block}
</body>
</html>
Translation of web application includes:
- translation of static texts and images (in templates, controllers)
- translation of database tables content (eg. posts, products etc)
- translation of URLs
Internationalization also provides the posibility to switch languages.
Languages available in the application are configured in /protected/config/config.php
file.
Any naming standard is better than no standard. What is important is to be consistent.
- Valid namespace format:
\<Vendor Name>\(<Namespace>\)*<Class Name>
- Class names MUST be declared in StudlyCaps
- Method names MUST be declared in camelCase
- Class constants MUST be declared in all upper case with underscore separators
- Code MUST use 4 spaces for indenting, not tabs
- Opening braces for control structures (if, for, etc.) must go on the same line and closing braces must go on the next line after the body
- Table name (plural):
my_products
- Field name:
first_name
- many-to-many relation table name:
order_has_product
- primary key column name:
id
- Collection name:
my_products
(plural) - Field name:
first_name
- Class name:
MyClassName
- JSON:
{ ‘this_is_a_key’: ‘value’ }
- Class name:
my-class-name
(like in Bootstrap) - In classes names avoid using general names like
.item
or.visible
(from Bootstrap), because it may case conflicts between various parts of the page. Be specific. Create unique selectors by including parents (.carousel .item
) or by using prefixes (.carousel-item
)
1: AngularJS Best Practices: Directory Structure by Adnan Kukic