-2

I want to connect articles to pages but i get error last screen.

enter image description here enter image description here enter image description here

ndm
  • 59,784
  • 9
  • 71
  • 110
Ross
  • 1
  • 5

2 Answers2

0

In your home page action

public function homepage() {
    $this->loadModel('Articles');
    $lastArticles = $this->Articles->find('all', ['limit' => 3, 'order' => 'Articles.created DESC'])->toArray();

$this->set('lastArticles', $lastArticles);

}

View::set expects 2 parameters, one being the name of the variable in the view and the 2nd being the values of that variable for the view.

0

You are in the PageController.php, I never used that controller for something else than the display() method. I don't know if what you're doing is the intended use.

If you want to list your articles I'd suggest you set that up in the ArticlesController.php.

//in src/Controller/ArticlesController.php
public function home() {
$lastArticles = $this->Articles->find('all', ['limit' => 3, 'order' => 'Articles.created DESC']);
  $this->set('lastArticles', $lastArticles);
} 

Then you need to create a view template named corresponding to the method name in the controller (see Naming Conventions) - for the method I posted it's "home.php".

//in templates/Articles/home.php
<?php foreach ($lastArticles as $lastArticle): ?>
//.. your fields ..
 <?php endforeach; ?>
ndru
  • 83
  • 1
  • 10