0

I'm a new student in CakePHP 3 please resolve my problem. This is my controller file:

DirectUseController.php

<?php
class DirectUseController extends AppController {
    function index() {
        $this->layout = 'directuse';
    }
}
?>

This is my layout file:

directuse.ctp

<!DOCTYPE html>
<html>
    <head>
        <title>
            <?= $this->fetch('title') ?>
        </title>
        </head>
    <body>
    <a href="#"> Bootstrap </a> | <a href="#"> Foundation </a> | <a href="#"> Materilize </a> 
    <br><br>
    Copyright
    <br><br>
  </body>
</html>

This is my index file in folder of direct use index.ctp

<section id="mainBody">
      hello 
</section>

and my folder structure is:
enter image description here

What am I missing?

1
  • Which version of cake you are using? Beqause when you used the latest version >3.4 $this->layout = 'directuse' will give a error. In that case you must use $this->viewBuilder()->setLayout('directuse');. Commented Aug 23, 2017 at 10:35

3 Answers 3

2

Your layout should presumably include this somewhere:

echo $this->fetch('content');

If that doesn't solve your problem, you're going to have to be more specific about what the problem is.

Sign up to request clarification or add additional context in comments.

Comments

0
  • CakePHP prioritizes convention over configuration, so try to change your Controller name to DirectusesController, change also your layout folder's name (to DirectUses) and maybe your Model too (cake bake can easily help you), I don't know your [table name in the database] but it should be plural and in lowercase (directuses) (if you don't use database that's another story)

  • For your template Greg Schmidt is right

Comments

0

Inside your layout file you have to use this:

<?= $this->Flash->render(); ?>
<?= $this->fetch('content'); ?>

I prefer to add the <html> and <body> tags inside the default.ctp or directuse.ctp layout. On this way you do not have to rebuild your html every time. This will make your code a lot cleaner.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.