Good day!
I am a new learner of using CakePHP framework. I just finished installing CakePHP and was trying to build a project using PhpStorm.
However, after running the application, I've got an Error Message on screen with regards to the SrcController
. I did follow the steps given on screen but after following them, I got this Error again...
Error: The view for SrcController::view() was not found.
I actually did some improvements now. But there's still an error... Here's my BooksController code:
<?php
/**
* @property BooksController $BooksController
*/
namespace App\Controller;
use App\Controller\AppController;
class BooksController extends AppController {
public function display()
{
$name = 'Book';
function index() {
$this->Book->recursive = 1;
$books = $this->Book->find('all');
$this->set('books', $books);
}
$this -> render('index');
}
}
?>
And here's my index:
<table>
<thead>
<th>ISBN</th><th>Title</th><th>Author</th>
</thead>
<?php foreach($books as $book): ?>
<tr>
<td><?php echo $book['Book']['isbn'] ?></td>
<td><?php echo $book['Book']['title'] ?></td>
<td><?php echo $book['Author']['name'] ?></td>
</tr>
<?php endforeach; ?>
</table>
And the error are:
Notice (8): Undefined variable: books [APP/Template\books\index.ctp, line 6]
Warning (2): Invalid argument supplied for foreach() [APP/Template\books\index.ctp, line 6]
Just try it
<?php
/**
* @property BooksController $BooksController
*/
namespace App\Controller;
use App\Controller\AppController;
class BooksController extends AppController {
public function display()
{
$name = 'Book';
function index() {
$this->Book->recursive = 1;
$books = $this->Book->find('all');
$this->set(compact('books));
}
$this -> render('index');
}
}
?>