Import Methods
this library is used to include asset files such as view, js, css, fonts. Libraries do not need to be included due to the auto installer feature of ZN Framework.
# Priority
The files are usually included from the respective directories located in the External/ and Projects/ directory. But what you need to know here is which directory will be included first in case of existence of files with the same name. The order is as follows.
1 - Projects
2 - External
The priority of file upload is internal structures. If there is no file here, this time External directory is checked. If the file does not exist in both directories, no inclusion will be made.
# Methods
# Usable [3.0.0]
Allows the content of the included files to be passed to the variable. Sometimes it may be necessary to send the content of one page as data to another page. It allows you to submit content pages as data to the masterpage, especially if you have designed your own masterpage. Its use is optional.
Parameters
bool $usable = true | Is it transferable? |
return this |
Usage
<?php namespace Project\Controllers;
use Import;
class Home extends Controller
{
public function main()
{
$content = Import::usable()->view('content');
$styles = Import::usable()->styles('mystyle', 'sitestyle');
View::content($content)->styles($styles);
}
}
# Data [3.0.0]
Used to submit data to included PHP pages. It does not have to be used as it is an optional method.
Parameters
array $data | array to contain data to send to views. |
return this |
It is used instead of the second parameter of the methods mentioned below.
Usage
<?php namespace Project\Controllers;
use Import;
class Home extends Controller
{
public function main()
{
$data =
[
'content' => Import::usable()->view('content'),
'styles' => Import::usable()->styles('mystyle', 'sitestyle')
];
Import::data($data)->view('home');
}
}
# View (1.0.0)
Allows views contained in the Views/ directory to be included.
Parameters
string $page | View path. No need to add .php or .wizard extension. |
array $data = NULL | The array of data to be sent to the view. |
bool $usable = false | Is the content of the view transferable? |
return mixed |
Usage
<?php namespace Project\Controllers;
use Import;
class Home extends Controller
{
public function main()
{
Import::view('home');
}
}
Data sending is done with the second parameter. The data to be sent to this parameter should be sent a string in the form of key => value
.
<?php namespace Project\Controllers;
use Import;
class Home extends Controller
{
public function main()
{
$content = Import::usable()->view('content');
$styles = Import::usable()->styles('mystyle', 'sitestyle');
Import::view('home',
[
'content' => $content,
'styles' => $styles
]);
}
}
For transferring to the variable, the 3rd parameter must be set to true or the usable (true) method must be used. If you are using the 3rd parameter and don't send data, you need to set the 2nd parameter to NULL or [].
<?php namespace Project\Controllers;
use Import;
class Home extends Controller
{
public function main()
{
$content = Import::view('content', NULL, true);
Import::view('home',
[
'content' => $content
]);
}
}
# Template (1.0.0)
Used to include files located in the Templates/ directory. Included directories are shown below.
Generally, these directories contain tables, charts, forms with html content with .php extension.
Parameters
string $page | Path of the template file to be called from the Resources/Templates/ directory |
array $data = NULL | The array of data to be sent to the view. |
bool $usable = false |
Is the content of the view transferable? |
return mixed |
Usage
<?php namespace Project\Controllers;
use Import;
class Home extends Controller
{
public function main()
{
$templateData =
[
'subject' => 'Example Subject',
'message' => 'Example Message'
];
$emailTemplate = Import::template('MyEmailTemplate', $templateData, true);
View::emailTemplate($emailTemplate);
}
}
# Style / Script (1.0.0)
Used externally to include style and script files with the .css or .js extension in the view. Since the usage of the Import::style() and Import::script() methods are exactly the same, the explanation has been taken only via Import::style().
If any theme directory (Resources/Themes/Default/) is activated with the Theme::active() method, the path information is used to include the style files created in it to show this active directory. If no theme is activated with this method, it starts specifying the path information in Resources/Themes/ directory. It is possible to include more than one file at the same time.
Suppose we have a sample file directory structure like the one below;
Resources/Themes/Blue/
site.css
contact.css
panel.css
Parameters
mixed ...$args | The path to the css file to be called from the Resources/Themes/ directory. |
return mixed |
Usage
If no theme activation has been performed, the following uses are included according to the above example directory structure by specifying the path to the Resources/Themes/ directory.
Import::style('Blue/site');
If we want to include multiple style files at the same time, we use it as follows.
Import::style('Blue/site', 'Blue/contact', 'Blue/panel');
Eğer tema aktif edilmişse bu defa yol bilgisi aktif edilen bu tema dizini gösterecek şekilde belirtilir.
Theme::active('Blue');
Import::style('site', 'contact', 'panel');
If we want to transfer the imported style file as data to a variable, the last parameter must be entered as true.
$style = Import::style('site', 'contact', 'panel' , true);
Settings/CDNLinks.php yapılandırma dosyasında yer alan link anahtarları ilgili stili yüklemek için kullanılabilir.
Import::style('bootstrap', 'awesome');
# Font (1.0.0)
Used to include font files embedded in the Resources/Themes/Any/ directory. The supported fonts are SVG, WOFF, OTF, TTF, EOT extensions. If desired, a different font type can be specified to support from the 'differentFontExtensions' => [] setting in Settings/Expressions.php settings file.
Parameters
mixed ...$args | The path to the font file to be called from the Resources/Themes/ directory. |
return mixed |
Usage
Variable transferability and Theme activation usage are like Import::style().
Import::font('Elips');
If we want to include multiple font files at the same time, we use it as follows. Multiple fonts can be included at the same time.
Import::font('Elips', 'Abode', 'Secrcode/secrcode');
If your font file has different types of extensions, they are also loaded.
Suppose you have a sample font file like the one below;
Resources/Themes/Blue/fonts/
akrobat.svg
akrobat.ttf
akrobat.eot
The usage below includes all of these fonts.
Import::font('fonts/akrobat');
Let's examine it on a simple code to better understand its usage.
<?php namespace Project\Controllers;
use Import;
class Home extends Controller
{
public function main()
{
Import::font('Akrobat/Black');
}
}
<div style="font-family:AkrobatBlack">Font Example</div>
# Something (1.0.0)
It is mostly used to include files with .php, .css or .js extensions other than standard directories (Views/, Resources/).
Parameters
string $page | The path of the file to be called from any directory. |
array $data = NULL | The array of data to be sent to the file. |
bool $usable = false | Is the content of the view transferable? |
return mixed |
Usage
Import::something(THEMES_DIR . 'site.css');
Import::something(EXTERNAL_THEMES_DIR . 'site.js');
Import::something(VIEWS_DIR. 'contact.php', ['data1' => 1, 'data2' => 2]);
$page = Import::something(VIEWS_DIR . 'contact.php', NULL, true);
this usage is also used for importing css and js.
# Recursive [3.0.0]
It is the optional method used to determine whether to perform internal index scanning. It is used instead of the second parameter of the Import::plugin() and Import::theme() methods.
Parameters
bool $recursive = true | Do you want to perform a recursive index scan? |
return this |
Usage
Import::recursive()->plugin('Bootstrap');
Import::recursive()->theme('BluePrint');
# Theme [3.0.0]
By specifying the name of the theme directory in the following directories, every file related to the theme in the directory is automatically loaded.
Parameters
mixed $theme | Theme name. |
bool $recursive = false | Do you want to perform a recursive index scan? |
bool $usable = false | Is the content of the view transferable? |
return mixed |
Usage
Import::theme('MyTheme');
Used to upload files located in all subdirectories within the specified directory. In other words, it scans within sub-directories. The 2nd parameter should be set to true or the recursive() method should be used.
Import::theme('Slider', true);
If you want to use it by passing it to a variable, the 3rd parameter should be set to true or the usable() method should be used.
Import::theme('Slider', false, true);
In order to include more than one file or directory, the first parameter is specified in the array data type. The array can contain a theme directory or files linked to the theme directory.
Import::theme(['BlueTheme', 'RedTheme', 'BlackTheme/black.css', 'style.css']);
In the above example usage, the following files are provided to be loaded.
● Resources/Themes/BlueTheme/ files.
● Resources/Themes/RedTheme/ files.
● Resources/Themes/BlackTheme/black.css file.
● Resources/Themes/style.css file.
# Plugin [3.0.0]
By specifying the name of the add-on directory in the following directories, every file related to the add-in in the directory is automatically loaded.
Parameters
mixed $plugin | Plugin name. |
bool $recursive = false | Do you want to perform a recursive index scan? |
bool $usable = false | Is the content of the view transferable? |
return mixed |
Usage
Import::plugin('MyPlugin');
Used to upload files located in all subdirectories within the specified directory. In other words, it scans within sub-directories. The 2nd parameter should be set to true or the recursive() method should be used.
Import::plugin('Slider', true);
If you want to use it by passing it to a variable, the 3rd parameter should be set to true or the usable() method should be used.
Import::plugin('Slider', false, true);
To be able to include more than one file or directory, the first parameter is specified in the array data type.
Import::plugin(['MyPlugins', 'bootstrap/bootstrap.css', 'bootstrap/boostrap.js']);
In the above example usage, the following files are provided to be loaded.
● Resources/Plugins/MyPlugins/ files.
● Resources/Plugins/bootstrap/bootstrap.css file.
● Resources/Plugins/bootstrap/bootstrap.js file.
# Handload [3.0.0]
It is used to include files containing php codes in the following directories. There is no need to specify an extension. It is especially useful for making necessary function definitions for your project.
Parameters
mixed ...$args | File name. |
return mixed |
Usage
Import::handload('funcFile1', 'funcFile2');