# Controller

TIP

The controller is generally responsible for performing a request action.

You can easily create controllers in ""Zest"" Framework goto App/Controllers/ form project root you have to create more controller here.

# Writing simple controller

<?php
namespace App\Controllers;
    use Zest\View\View; //you will learn more about view in later this is for accessing view
class Home extends \Zest\Controller\Controller
{

    public function index()
    {

        echo View::view("Home/index"); //you will learn more about view in later this is for accessing view

    }

}

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

This is easy way for creating controllers this create home page

# Complex way for writing controller

<?php

namespace App\Controllers;

use Zest\View\View; //you will learn more about view in later this is for accessing view

class About extends \Zest\Controller\Controller
{

    public function index()
    {
        echo $this->route_params['username']; //$this->router_params use for accessing paramter begin passed for more information see https://github.com/Softhub99/Zest/wiki/Routing#router-with-complex-parameter
    }
    public function about()
    {
        echo view::SetTemplate("Home/index.html",[
    'header' => 'PHP Template engine',]); //you will learn more about view/template engine in later this is for accessing view
    }

}

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
Last Updated: 3/22/2022, 4:20:26 PM