Table of Contents
Create Application
This chapter describes application and module directory structure. Also you can learn how to create your own module step by step.
Directory structure
Application structure
|
Directory/file |
Description |
||||||||
|
|
Application configuration directory. The default configuration is placed in application/configs/application.ini, and contains some basic directives for setting your PHP environment (for instance, turning error reporting on and off), indicating the path to your bootstrap class (as well as its class name), and the path to your action controllers. |
||||||||
|
|
Contains common layouts like error.phtml for error handler. |
||||||||
|
|
For storage modules language translations. Example: |_ en |
||||||||
|
|
Modules directory. |
||||||||
|
|
Temporary files directory.
|
||||||||
|
|
Contains common templates. |
||||||||
|
|
Application bootstrap. |
Module structure
Module structure
Each module should observe the convention of directories. Next informational table describes it.
|
Directory |
Description |
|||||
|
|
Components directory contains module components that can be used directly in other modules. Usually needed for display cross-module information blocks, widgets, text information, forms (such as login form) and so on. You can run components from any place in your application: controllers, models, views, bootstraps, libraries if it needed. While creating component simply extend your class with Singular_Component_Abstract. To execute component use following code example: Singular_Component::run('CompName', 'module', $compOptions); |
|||||
|
|
Your application's action controllers contain your application workflow, and do the work of mapping your requests to the appropriate models and views.
|
|||||
|
|
Form classes that will be used to render html forms including various filters and validators in templates. |
|||||
|
|
Directory for storing event handlers. Classes must be an instance of Singular_Event_Listener_Abstract. See Events & Handlers chapter for information how to create and use event handlers. |
|||||
|
|
Directory for storing view helpers that will be used by current module. |
|||||
|
|
Store your models and mappers in the root of "models" folder.
|
|||||
|
|
View scripts directory. The filename convention for auto-rendering is following: moduleName_controllerName_actionName.phtml. You can also use arbitrary filename for your module templates, for example: |
|||||
|
|
Language keys file in php array format. |
|||||
|
|
Module information file. |
|||||
|
|
Route definitions in ini format. Example:
portfolio_category.type = Zend_Controller_Router_Route_Regex
portfolio_category.route = "category(\d+)/portfolio(\d{0,})\.html"
portfolio_category.defaults.module = portfolio
portfolio_category.defaults.controller = frontend
portfolio_category.defaults.action = index
portfolio_category.map.1 = category_id
portfolio_category.map.2 = page
portfolio_category.reverse = "category%s/portfolio%s.html"
|
Module name
Module name can consist with letters, digits, - and _ symbols, but not only with digits and -, _ symbols.
Correct module names:
- search
- listings
- look4ward
- support24
- 4x4wheels
- hot-tours
Bad module names:
- jack_daniels
- bob&joe store
- ruby on rails
- 100%respect
- sport#major
- club$metro
- 44400222
- 1+3=4
For example we take "test" (without quotes) name for our module.
Add an empty directory with name "test" as your module name into application/modules directory.
Adding module controllers
Add "controllers" directory to the module as seen on "Image 2".

Image 2. Module controller directory
Let's create Index Controller as your main module controller that should handle some actions. See "Image 3".

Image 3. Creating Index controller
Firstly you need to create abstract controller application/modules/test/controllers/Abstract/Index.php as follows:
abstract class Test_Controller_Abstract_Index extends Singular_Controller_Action
{
/**
* Index action
*
* @return void
*/
public function indexAction()
{
// action code body will be here
}
}
Then create simple controller application/modules/test/controllers/IndexController.php and extend it from abstract controller Test_Controller_Abstract_Index. This controller can't be modified except this module authors. Use simple controller instead.
URLs:
/**
* Index controller for test module
*
* @see Test_Controller_Abstract_Index
*/
class Test_IndexController extends Test_Controller_Abstract_Index
{
}
Prefix "Test_" in simple controller class name specifies in an accessory to the module "test". This will be an empty class that only inherits actions from Test_Controller_Abstract_Index. Developers can use this controller to modify default actions from abstract controller.
SingularCORE provides to developers two controller types such as "frontend" and "admin". Example controller above has public "frontend" controller type. Lets see how to create "admin" controller type.
To create admin controller you only need to specify "Admin" prefix in your controller name.
Create abstract admin controller application/modules/test/controllers/Abstract/Admin.php:
abstract class Test_Controller_Abstract_Admin extends Singular_Controller_Action
{
/**
* Index action
*
* @return void
*/
public function indexAction()
{
// action code body will be here
}
}
After create simple controller application/modules/test/controllers/AdminController.php:
URLs:
/**
* Index controller for test module
*
* @see Test_Controller_Abstract_Admin
*/
class Test_AdminController extends Test_Controller_Abstract_Admin
{
}
Thats all! Now you have public "frontend" controller and "admin" controller.
If you need additional admin controller simply add "Admin" prefix to controller name application/modules/test/controllers/Abstract/AdminCategories.php.
abstract class Test_Controller_Abstract_AdminCategories extends Singular_Controller_Action
{
/**
* List action
*
* @return void
*/
public function listAction()
{
// action code body will be here
}
}
And finally simple controller application/modules/test/controllers/AdminCategoriesController.php:
URLs:
/**
* AdminCategories controller for test module
*
* @see Test_Controller_Abstract_AdminCategories
*/
class Test_AdminCategoriesController extends Test_Controller_Abstract_AdminCategories
{
}

