Welcome Guest, Not a member yet? Register   Sign In
extend layout
#4

(This post was last modified: 11-11-2021, 09:51 AM by ikesela.)

layout.php (in App\VIew folder)
Code:
<!doctype html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0,shrink-to-fit=no">
    <title><?=Lang('Lang.app')?></title>
    <link href=...css.css" rel="stylesheet" type="text/css" />   
  </head>
<body> 
<div class="container"> 
<main role="main"> 
<?= view($config->views['direct_view']) ?> 
<?= $this->renderSection('main') ?>
</main>  
</div>  
<script src=".....js"></script>

some_file.php
Code:
<?= $this->extend($config->viewLayout) ?>
<?= $this->section('main') ?>
.. YOUR CONTENT HERE ...
<?= $this->endSection() ?>

your_controller
Code:
public function your_function()
{
              $config = config('YourConfig'); // can do this in contructor instead

return view($config->views['your_view'],[
'config' => $config,
                      'data' => $any_data_to_pass,
]);
}

YourConfig.php (in App|config folder)
Code:
namespace App\Config;

use CodeIgniter\Config\BaseConfig;

class YourConfig extends BaseConfig
{
 
    // you can have multiple view setting here
    public $views = [
         'direct_view' => 'App\Views\some_folder\direct_render_file_in_layout'
        'your_view' => 'App\Views\some_folder\some_file', // link to real file with extension .php 
    ]; 
  public $some_parameter = 'your_value';
    // Layout for the views to extend
    public $viewLayout = 'App\Views\some_folder\layout';
}

Routes.php
 
Code:
$routes->get('/', 'YourController::your_function');
 

I hope this can give you hint how the layout basic work and load it as single page web

You can edit file App\View\errors\html\error_404.php for custom not found page and remove default message.
Reply


Messages In This Thread
extend layout - by nemesis - 11-10-2021, 09:18 AM
RE: extend layout - by InsiteFX - 11-11-2021, 03:12 AM
RE: extend layout - by nemesis - 11-15-2021, 08:49 AM
RE: extend layout - by nemesis - 11-11-2021, 07:26 AM
RE: extend layout - by ikesela - 11-11-2021, 09:45 AM
RE: extend layout - by nemesis - 11-11-2021, 03:20 PM
RE: extend layout - by kenjis - 11-12-2021, 11:33 PM
RE: extend layout - by nemesis - 11-13-2021, 01:40 AM
RE: extend layout - by kenjis - 11-15-2021, 06:40 PM
RE: extend layout - by nemesis - 11-16-2021, 12:58 AM
RE: extend layout - by kenjis - 11-16-2021, 01:16 AM
RE: extend layout - by nemesis - 11-16-2021, 08:33 AM
RE: extend layout - by kenjis - 11-16-2021, 03:58 PM
RE: extend layout - by nemesis - 11-17-2021, 11:02 AM



Theme © iAndrew 2016 - Forum software by © MyBB