Naming Conventions in Nooku – I
Friday, August 26, 2011 4:39With Great power comes great responsibility, yes! it fits aptly with Nooku Framework. To leverage the power of Nooku, it requires you to follow some conventions for naming your classes, files, folders, tables and fields too. Let us explore more about these naming conventions in detail. We will divide this post in four sections and we will also see how we can easily adapt ourselves to these naming conventions.
Classes Naming Convention
It depends on what you are naming, it varies if you are naming a component or module or a plugin. If the class is a part of Component, the general syntax is Com<YourComponentName><M/V/C><FileName>.
For Example: Let us consider, we have a component named CoolBanner. If we want to define a Banner Controller the class name should be ComCoolbannerControllerBanner. And if we want to define a model class, the class name should look like ComCoolbannerModelBanner.
But there are other things to consider when naming your class. But to understand better, we can say the naming of the class depends on the folder structure of your component and filename that will contain your class. You will generally store all your controllers in controllers folder of your component, all models in models folder, filters in Filters folder and like wise views in your views folder. (Views classname are exception to above syntax)
Lets us review how this folder structure and class naming map to each other. As per above example, we should store
ComCoolbannerControllerBanner in /component/com_coolbanner/controllers/banner.php
ComCoolbannerModelBanner in /component/com_coolbanner/models/banner.php
ComCoolbannerModelBanners in /component/com_coolbanner/models/banners.php
ComCoolbannerFilterBannerid in /components/com_coolbanner/filters/bannerid.php
Also if you have some extra level deep folders like /components/comcoolbanner/databases/ we should write the classname that reflects this level too. So for example, let us assume we have 3 folders in /components/comcoolbanner/databases/ folder namely tables , behaviors and rowsets and also have categories.php, hits.php and categories.php in these folders in order. The class name should reflect these folder structure.
ComCoolbannerDatabaseTableCategories should go in /components/com_coolbanner/databases/tables/categories.php
ComCoolbannerDatabaseBehaviorHits Should go in /components/com_coolbanner/databases/behaviors/hits.php
ComCoolbannerDatabaseRowsetCategories Should go in /components/com_coolbanner/databases/rowsets/hits.php
Views are exception to this naming convention. A View’s filename uses the document type that is being used to render the view. The class ComCoolBannerViewBannersHtml will render HTML document type for the banners view and should be stored in the file /components/comcoolbanner/views/banners/html.php. You can even add your own document type format at will. For example if you want a view to be rendered as json, you can create a view class ComCoolbannerViewBannersJson and store it in /components/comcoolbanner/views/banners/json.php
Likewise you can name your classname depending on the folder structure.
You can even follow the above naming convention to name your modules and plugins as well. The only deviation from above syntax is the prefix used to start class name. Modules start with Mod, Plugins start with Plg and Components Start Com. See below
ModCoolbannerDefault will be stored in /modules/mod_coolbanner/default.php
ModCoolbannerView will be stored in /modules/mod_coolbanner/view.php
PlgSystemCoolbanner will be stored in /plugins/system/coolbanner.php
PlgSystemCoolbannerDefault will be stored in /plugins/system/coolbanner/default.php
And likewise.
We will continue the next part of this series in my next post. We will discuss about table and field naming convention in nooku. I hope this was useful for people starting with nooku. Best of luck.
















Sergey says:
August 27th, 2011 at 10:32 am
Cool, so interesting. Please, continue.
joomlahenry says:
January 7th, 2012 at 1:05 am
You will generally store all your controllers in controllers folder of your component .improving our quality of joomla design service and better support delivery.