URI Structures



In a project developed with ZN Framework, the request is made to a sample web address as below. Understanding the URL structure used with ZN is very important to understand the use of ZN Framework.

URL
Basic Section Relative Section Rotatable Section
http[s]:// yourdomain.com/ [project-name/] [lang/] [controller/] [function/] [param1/param2 ...]

The URL sections above are reviewed in stages below.

 

 

# Section Headings


# HTTP/S

# HTTPS Conversion
# Change Port
# Catching HTTP

# Domain Name

# With HTTP

# Project Name

# Predefined Project Directory
# Use of Aliases
# Catching Project Directory

# Lang

# Change Language
# Catching Active Language

# Controller

# Predefined Controller
# Catching Controller Name

# Function

# Predefined Method
# Catching Method Name

# Parameters

# Catching Parameters

 

 

# HTTP/S


The URL::site() method is used to create an on-site URL in the ZN Framework. The http:// prefix of the links created with this method changes to https:// if SSL certificate is activated on the site. This conversion is done automatically. There is no need for an extra setting for this. Therefore, all links used on the site must be made with URL::site(). If the link will point to a local file such as a .css or .js, then URL::base() should be used instead of URL::site().

echo URL::site('product/list');
http://localhost/eip/example/product/list
HTTPS Conversion

When you install a security certificate on your site, links automatically convert from http to https.

echo URL::site('product/list');
https://localhost/eip/example/product/list
Change Port

If a port other than 443 is used for HTTPS in IIS servers, the following arrangement should be made in order for the links to turn into https automatically.

File: zeroneed.php
# Before ZN::run() method
$_SERVER['SERVER_PORT'] = 443;

It must be manipulated to ensure the correct match of the SSL port.

Catching HTTP

You can use the method below to get this value of the URL.

echo Request::scheme();
http

 

 

# Domain Name


You can use the Http::host() method to get this value.

echo Http::host();
localhost
With HTTP

You can use the following method to capture the value of http://localhost.

echo URL::host();
http://localhost

 

 

# Project Name


It is the section containing the names of the project directories in the Projects/ directory to be run. If the directory to be run is the default (Frontend/) directory, it will not be written. The directory name is written to run directories found outside of it. If the Frontend/ directory is predefined, typing the hostname directly is sufficient to run that directory.

Run: localhost/

However, if a different project directory is requested to be run, it is specified in the URL.

Run: localhost/Backend/

The above request runs the Projects/Backend/ directory.

Predefined Project Directory

The project directory that is run by default is the Projects/Frontend/ directory. To change the default opening project directory, you can make the necessary settings from the configuration file below.

File: Settings/Projects.php -> directory:default
'default' => 'Frontend'
Use of Aliases

You can give aliases to represent these directory names to access your project directories. Use the following config file to edit this setting.

File: Settings/Projects.php -> directory:others
'panel' => 'Backend'

You can now run the Backend/ directory.

Run: localhost/panel/

You can find detailed information about what this section is used for in the Multiple Project Development section.

Catching Project Directory

If the project directory name being executed on the URL is required, the corresponding project name is obtained with the CURRENT_PROJECT constant.

echo CURRENT_PROJECT;
Frontend

 

 

# Lang


this section is closed by default. Shows the site's selected language value. In order for the selected language abbreviation to be displayed on the URL, it must be activated from the configuration file. If this is done, the links created with the URL::site() method will also receive this language suffix. In order for the language attachment to be viewable on the URL, it must be activated from the configuration file whose path is specified below.

File: Projects/Frontend/Config/Services.php -> uri:lang
'lang' => true

Now the URL::site() method produces the following output.

echo URL::site('product/list');
http://localhost/en/product/list 
Change Language

The Lang::set() method is used to change this value.

Lang::set('tr');

echo URL::site('product/list');
http://localhost/tr/product/list 

this change is also possible by users changing this value and running it through the URL.

Catching Active Language

The Lang::get() method is used to capture the currently selected language shortening.

echo Lang::get();
tr

The explanation for this section has been made in the File Language Library link.

 

 

# Controller


this section determines which controllers in the Controllers/ directory in the ZN Framework will be run. The controller that works by default for requests made without specifying a controller name is the Home controller. The explanation for this section has been made in the Controllers link.

Predefined Controller

You can use the following configuration file to change the default controller information.

File: Project/Frontend/Config/Routing.php
'openController' => 'Home'
Catching Controller Name

The constant CURRENT_CONTROLLER must be used to capture the controller name. Although it can be accessed by different methods, it gives the name of the real controller since it is not affected by fixed routes.

echo CURRENT_CONTROLLER;
product
Warning: CURRENT_CONTROLLER gives the controller's file name without extension. Therefore, it is affected by the filename of the controller.

 

 

# Function


this section refers to the function information of the controller expressed in the previous section. In requests made without specifying a method name, the related controller's main method is activated. Again, the explanation about the use of this section is made in the Controllers link.

Predefined Method

You can use the following configuration file to change the default controller method information.

File: Project/Frontend/Config/Routing.php
'openFunction' => 'main'
Catching Method Name

The constant CURRENT_CFUNCTION must be used to capture the method name. This constant gives the name of the actual function currently being executed. This is not affected by fixed routes.

echo CURRENT_CFUNCTION;
list

 

 

# Parameters


It is the part used to send data to the method of the operated controller. This and all of the following sections are used for parameter passing.

Catching Parameters

The CURRENT_CPARAMETERS constant can be used to capture parameters. Apart from this constant, you can also capture parameters with sequential variables that you define for the parameters of the related method.

URL: localhost/product/list/20/example/value
output( CURRENT_CPARAMETERS );
0 => string '20' ( length = 4 )
1 => string 'example' ( length = 9 )
2 => string 'value' ( length = 7 )