Welcome Guest, Not a member yet? Register   Sign In
Render layout and access variables
#1

Hi guys, very new in CI4 (2 days) but long time user in CI3...
I am struggling for some days using layout funcionality. Cant render the layout completely and cant access to settings variable defined in main.php that is the template. in this case, I cant see lista.php when the template is rendered on screen but no error. If I try to access $settings inside lista.php or boda.php I have an error saying that $settings is not defined, strange because all extends main.php
Can someone point me what I am doing wrong?
Thanks!
Jorge

My controller is like
Code:
    public function index()
    {
        $_SESSION['userdata']['grupo'] = 'CL';
        return  view('boda');
    }
My template main.php in views\template is
PHP Code:
<!DOCTYPE html>
<
html>
<
head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
<
script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM" crossorigin="anonymous"></script>
    <title></title>
</
head>
<
body>
  <?php $settings = new \Config\Ncweb(); ?>
<nav class="navbar navbar-expand-lg bg-light">
  <div class="container-fluid">
    <a class="navbar-brand" href="#">Navbar</a>
    <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
      <span class="navbar-toggler-icon"></span>
    </button>
    <div class="collapse navbar-collapse" id="navbarSupportedContent">
      <ul class="navbar-nav me-auto mb-2 mb-lg-0">
        <li class="nav-item">
          <a class="nav-link active" aria-current="page" href="#">Home</a>
        </li>
        <li class="nav-item">
          <a class="nav-link" href="#">Link</a>
        </li>
        <li class="nav-item">
          <a class="nav-link disabled">Disabled</a>
        </li>
      </ul>
    </div>
  </div>
</nav>
<div class="container">
  <?= $this->renderSection('templates/lista'?>
  <?= $this->renderSection('content')?>
</div>
<script src="https://cdn.jsdelivr.net/npm/@popperjs/[email protected]/dist/umd/popper.min.js" integrity="sha384-IQsoLXl5PILFhosVNubq5LC7Qb9DXgDA9i+tQ8Zj3iwWAwPtgFTxbJ8NT4GN1R8p" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.min.js" integrity="sha384-cVKIPhGWiC2Al4u+LWgxfKTRIcfu0JTxR+EQDz/bgldoEyl4H0zUF0QKbrJ0EcQF" crossorigin="anonymous"></script>
</body>
</html> 
My lista.php in views/templates is
PHP Code:
<?=$this->extend('layouts/main')?>
<?=$this
->section('lista')?>
<ul class="list-group">
  <li class="list-group-item">An item</li>
  <li class="list-group-item">A second item</li>
  <li class="list-group-item">A third item</li>
  <li class="list-group-item">A fourth item</li>
  <li class="list-group-item">And a fifth one</li>
</ul>
<?=$this->endSection()?>
And my file boda.php in views is
PHP Code:
<?=$this->extend('layouts/main')?>
<?=$this
->section('content')?>
this is content
<?=$this->endSection()?>
Reply




Theme © iAndrew 2016 - Forum software by © MyBB