0

How to create block with "latest articles" with CakePhp 3.x? I'm learning by "blog tutorial" from official web-site.

I already have controller "Articles" from tutorial:

// src/Controller/ArticlesController.php

namespace App\Controller;

use App\Controller\AppController;

class ArticlesController extends AppController
{

    public function initialize()
    {
        parent::initialize();

        $this->loadComponent('Flash'); // Include the FlashComponent
    }

    public function index()
    {
        $this->set('articles', $this->Articles->find('all'));
    }

    public function latest()
    {
        $this->set('articles', $this->find('all')->limit(5));
    }

    public function view($id)
    {
        // view article
    }

    public function add()
    {
        // Add article
    }
}

How I can create something like "sidebar with 5 latest articles" and insert it directly to "layout"? (homepage layout for example, not controller page). I must create "block" or "element"? Do you have an example please?

halfer
  • 19,824
  • 17
  • 99
  • 186

0 Answers0