- Ness
- System
- View
- System
You can include this library to your code file by typing the below code;
use Ness\System\View
About Views #top
Views are html pages that can be loaded by a controller, you can not directly redirect your application to a view file. Ness PHP stores view files in a folder called 'View'. You can create sub folders in view folder if you want to seperate parts of your application.
Render a View #top
Render command can be used to create a view from php view file and load to browser screen.
$this->View->Render(string $prm_file,boolean $isusual = true);
Return a view to user. | ||
Return | Object | |
Parameters | $prm_file String; View's file name which is located in 'View' path $isusual Boolean; *optional. If your view is not located in 'View' directory. |
Render Content #top
Render command can be also used for rendering string messages to browser screen.
$this->Content->Render(string $prm);
Return a view to user. | ||
Return | Object | |
Parameters | $prm String; Value to print |
Check if a View is Available #top
This command is used to check if a view file is available, returns true if file is found.
$this->View->isAvailable(string $prm_file,boolean $isusual = true);
Check if view file is available | ||
Return | Boolean | |
Parameters | $prm_file String; View's file name which is located in 'View' path $isusual Boolean; *optional. If your view is not located in 'View' directory. |
Transfer Values Between Controller/View #top
Let's say you have a indexController.php controller in your controller directory, and you want to set a variable in your view file. There is lots of methods to do that like ObjectMapper of Ness framework, but in classic way you need to define a variable in your view file;
...HTML CODES
<?= $this->sayhello; ?>
...HTML CODES
And in your controller;
class indexController extends Ness\Controller{
public function IndexAction($param=0)
{
$this->View->sayhello = "Hello World :)";
$this->View->Render("test.php");
}
}
Examples #top
Check if View file is available
$this->View->isAvailable("home\index.php");
will look for Application/View/home/index.php
Check if view file is anywhere else
$this->View->isAvailable("test_folder\index.php", false);
will look for Application/test_folder/index.php
Load if view exists
if($this->View->isAvailable("home/home.php"))
{
$this->View->Render("home/home.php");
}else{
$this->Content->Render("View Not Found");
}