Views



Views are web pages that are mainly composed of HTML codes that users are comparing . View pages Controllers/ contained in the directory is managed by the controller page and Projects/Any/Views/ directory created in. So while our PHP code is mostly in control, our HTML code is in the views.

 

# Section Headings


# View Installation Methods
# Create View page
# View Visit the Include Page
# The page Included in the Data View Post

# Send Data to All Views

# Automatic File Upload ( ZN> = 4.3.0 )

# Auto Uploading in Sub-Methods
# Data Send

# Automatic Installation in Directory Form ( ZN> = 5.0.0 )

# Auto Uploading in Sub-Methods
# Data Send

# Send Data to Automatically Uploaded Views ( ZN> = 5.0.0 )
# Brief Usage of Import Referrals ( ZN> = 5.2.6 )
# Best Practice

# Scenario
# Directory Structure
# Use

 

# View Upload Methods


The views can be loaded in 3 ways by the controllers.

1 - Manual Upload
2 - Automatic File Upload  ( ZN> = 4.3.0 )
3 - Automatic Directory Upload ( ZN> = 5.0.0 )

 

# Create View Page


It needs to be created before views can be loaded by the controllers. Examples Now Views/ directory into homepage.php and content.php is 2 Create pieces file and edit the contents as follows.

File: Projects/Frontend/Views/homepage.php
<html>
    <head>
        <title><?php echo $title ?></title>
    </head>

    <body>
        <?php echo $content ?>
    </body>
</html>
File: Projects/Frontend/Views/content.php
This is Content Page!

# Include View Page


The generated views need to be called by the relevant controllers in order to be able to run them via the URL. Import :: page () or Import :: view () command is used to call the views in the Views / directory . Apart from these methods, it is also possible to automatically load views.

Import::page('homepage');
// Or
Import::view('homepage');
// Or
View::get('homepage'); // ZN >= 5.2.7
Note: If the page you want to include is a .php extension, you do not need to use the .php extension.


Let's show howthe view in the Views/ directorywill be included by the controller in the Controllers/ directory.

File: Projects/Frontend/Controllers/homepage.php
<?php namespace Project\Controllers;

use Import;

class Homepage extends Controller
{
    public function main()
    {
        Import::view('content');
    }
}
Run: localhost/homepage

You can see that the Views/content.php file has been uploaded by the respective controller.

This is Content Page!

 

# Send Data to Included View Page


Data is sent to the generated views through the controllers. Because the main objects that will shape the appearance are the data prepared and sent by the controllers. Below is a sample code that demonstrates how to do this.

File: Projects/Frontend/Controllers/homepage.php
<?php namespace Project\Controllers;

use Import;

class Homepage extends Controller
{
    public function main(...$parameters)
    {
    	$data['title']   = 'Welcome to Web Page'; 
        $data['content'] = Import::usable()->view('content');
        
    	Import::view('homepage', $data);
    }
}

Above Views / homepage.php2 data have been sent to the view . Of these, 1 have a simple string while expressing 2. si Views / content.php the content of the view. The usable () method has been used to transfer this content to the variable . you createdViews / homepage.phpThe view contains 2 variables named $ title and $ content . These variables represent the key expressions of the directory sent as $ data above .

Run: example.com/homepage
This is Content Page!

Send Data to All Views

Submissions with the View :: class also send data to all view pages currently loaded. Thus, there is no need to resend for nested views.

 View::example('Example Data');

 $page = Import::view('content');

 Import::view('home', ['page' => $page]);

In the above usage View :: example () both with the use of content as well as homWe sent $ example data to e views .

 

# Automatic File Upload ( ZN> = 4.3.0 )


If you do not want the controls to load the views with the import :: view () method, create the same named view page with the controller name.

Controller: Projects / Frontend / Controllers / example.php
View: Projects / Frontend / Views / example.php

Example :: The main () method will automatically load the view page when run.

Auto-loading in Sub-Methods

If you want to automatically load pages into sub functions, you use them as follows.

View: Projects / Frontend / Views / controllerFileName-methodName.php

That -is, you must specify the function name along with the page name .

Data Sending

You can use the View library to send data. This library does not need to be specified with use because the namespace value is the same as the controller.

File: Projects / Frontend / Controllers / example.php
<?php namespace Project\Controllers;

class Example extends Controller
{
    public function main(String $params = NULL)
    {
         View::pageName('Example Page');
    }

    public function try()
    {
         View::pageName('Example Try Page');
    }
}
File: Projects / Frontend / Views / example.php
Example Page
File: Projects / Frontend / Views / example-try.php
Example Try Page

 

# Automatic Installation in Directory Form ( ZN> = 5.0.0 )


This method is used in situations where you want to categorize these views under the directory by controller name when the number of views increases by the file form method. To enable this method, you need to set the viewNameType value to 'directory' under Config / ViewObjects.php configuration file .

Controller: Projects / Frontend / Controllers / example.php
View: Projects / Frontend / Views / example / main.php

Example :: The main () method will automatically load the view page when run.

Auto-loading in Sub-Methods

If you want to automatically load pages into sub functions, you use them as follows.

View: Projects / Frontend / Views / controllerFileName / methodName.php

So the controller name should be the directory name in Views / . The methods in the controller must be the filename in that directory.

Data Sending

You can use the View library to send data . This library does not need to be specified with use because the namespace value is the same as the controller .

File: Projects / Frontend / Controllers / example.php
<?php namespace Project\Controllers;

class Example extends Controller
{
    public function main(String $params = NULL)
    {
        View::pageName('Example Page');
    }

    public function try()
    {
         View::pageName('Example Try Page');
    }
}
File: Projects / Frontend / Views / example / main.php
0 10px; padding: 9.5px; word-break: break-all;
File: Projects / Frontend / Views / example / try.php
0 10px; padding: 9.5px; word-break: break-all;

 

# Data Upload to Auto Upload Views ( ZN> = 5.0.0 )


Sending data to auto-uploaded views  is done with the View library. The name of the data to be sent in the method name of this library is written in the parameter. The sample usage is as follows.

File: Projects / Frontend / Controllers / example.php
<?php namespace Project\Controllers;

use Import;

class Example extends Controller
{
    public function main()
    {
         View::email('example@example.com');
         View::example(['example' => 'Example']);
         View::otherPage(Import::usable()->view('other'));
    }
}

The above uploaded 3 data have been sent. $ email, $ Example and $ Otherpag to

 

# Brief Usage of Import Calls ( ZN> = 5.2.6 )


By the specified version , you can send views uploaded with View library and import methods in a shorter time.

<?php namespace Project\Controllers;

use Import;

class Example extends Controller
{
    public function main()
    {
         // Data olarak görünüm gönderimi.
         View::other('view:other', ['otherPageData' => 'Other Page Data']);

         // Data olarak script gönderimi.
         View::exampleScript('script:example');
    }
}

In the above usage otherIt is content with a view of the example of a named script file html use the data we sent automatically loaded view.

 

# Best Practice


Below is a sample of the best controller usage and data transmission. We recommend to automatically load the directory form, so we have configured the predefined setting accordingly. The best practice is only for controller use and data transmission. Not for appearance.

Scenario

There will be a number of sample data sent by a controller that is automatically loaded in the directory form. One of these files will be another look page.

Directory Structure

Build your files and directories according to the following structure.

Controllers /

home.php

Views /

home /

main.wizard.php

sections /

banner.wizard.php

 

Use

Design your controller as follows.

Controller: Projects / Frontend / Controllers / home.php
<?php namespace Project\Controllers;

class Home extends Controller
{
    public function main(String $params = NULL)
    {
        View::title('Home Page')
            ->banner('view:sections/banner')
            ->message('Welcome To Home Page');
    }
}

Design your present content as follows.

View: Projects / Frontend / Controllers / home / main.wizard.php
<html>
    <head>
        <title>Example</title>
    </head>
    <body>
        <p> $title </p>
        <p> $banner </p>
        <p> $message </p> 
    </body>
</html>

Design the contents of the other viewpoint as follows.

View: Projects / Frontend / Controllers / sections / banner.wizard.php

Run the control over the URL.

Run: localhost / home
Home Page
Banner Page
Welcome To Home Page