About Creating Area #top
Ness framework supports creating areas. In Ness framework an area means a smaller functional unit of your project. You can create areas in controllers folder for dividing the business logic of your application. This topic will guide you to create a unit using areas and manage your view files for controllers in areas.
Area in Controllers #top
For creating an area you need to create a sub-folder in controllers folder. If you need to divide your project for admin backend you need to follow the steps below.
- Create a sub-folder in 'Controller' folder.
- Your folder name must contain the Area suffix
- Create controllers in your area
Let's say we need to create an admin panel. In controllers folder we need to create a folder called 'adminArea'. The rest part is the same logic with creating controllers You can check controllers for more information.
Area in Views #top
It is not necessary to create a sub-view folder for every area but you can create folders under 'View' path. By this way you can divide the views and controllers for smaller units.
Redirect to Area #top
Redirecting to controllers in areas you need to use the following method; Assume that you need to redirect your user to admin panel's login page. Create a tag and in href attribute print the url by this method:
/** OTHER CODES **/
<a href=" <?= Ness\Url::RedirectToArea("areaName", "ControllerName", "ActionName", "optianl-Parameters for function"); ?>"> Link Name < /a>
< a href=" <?= Ness\Url::RedirectToArea("admin", "user", "login"); ?>"> Admin Login < /a>
/** OTHER CODES **/
the code above will return a string to href attribute:
http://sitename.com/user/login/?p=admin