如何使用 CakePhp 3.x 创建带有“最新文章”的块?我正在通过官方网站的“博客教程”学习。
我已经有教程中的控制器“文章”:
// 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
}
}
如何创建“带有 5 篇最新文章的侧边栏”并将其直接插入“布局”?(例如主页布局,而不是控制器页面)。我必须创建“块”还是“元素”?请问你有例子吗?