I want to know why $Articles will not be generate

Viewed 64

In CakePHP tutorial, I want to make Articles, but I do not know.

I am working on cakePHP, along this, a error says Call to a member function find() on boolean

This is ArticleController

<?php
namespace App\Controller;
use App\Controller\AppController;

class ArticleController extends AppController {
    public function index() {
        $this->loadComponent('Paginator');
        debug($this->Articles);
        $articles = $this->Paginator->paginate($this->Articles->find());
        $this->set(compact('articles'));
    }
    public function edit() {
        $article = $this->Articles->findBySlug($slug)->firstOrFail();
        if ($this->request->is(['post', 'put'])) {
            $this->Articles->patchEntity($article, $this->request->getData());
            if ($this->Articles->save($article)) {
                $this->Flash->success(__('Your article has been updated.'));
                return $this->redirect(['action' => 'index']);
            }
            $this->Flash->error(__('Unable to update your article.'));
        }
        $this->set('article', $article);
    }
    public function view($slug = null)
    {
        $article = $this->Articles->findBySlug($slug)->firstOrFail();
        $this->set(compact('article'));
    }

}

This is Article index

<!-- File: src/Template/Articles/index.ctp -->

<h1>Articles</h1>
<table>
    <tr>
        <th>Title</th>
        <th>Created</th>
    </tr>

    <!-- Here is where we iterate through our $articles query object, printing out article info -->

    <?php foreach ($articles as $article): ?>
    <tr>
        <td>
            <?= $this->Html->link($article->title, ['action' => 'view', $article->slug]) ?>
        </td>
        <td>
            <?= $article->created->format(DATE_RFC850) ?>
        </td>
    </tr>
    <?php endforeach; ?>
</table>

and this is model.

<?php
// src/Model/Entity/Article.php
namespace App\Model\Entity;

use Cake\ORM\Entity;

class Article extends Entity
{
    protected $_accessible = [
        '*' => true,
        'id' => false,
        'slug' => false,
    ];
}

I copied all of them, searched this article a lot, but cannot find where the Articles came from. Please teach me ><

1 Answers

I think

class ArticleController extends AppController

should be

class ArticlesController extends AppController

Also, filename should be ArticlesController.php, in my opinion.

Related