Я только что закончил этот урок с http://www.sitepoint.com/application-development-cakephp/, когда я начинаю свой первый проект cakephp в понедельник, и я получаю ряд ошибок и предупреждений, касающихся findAll()
и foreach()
.
Вот ошибки:
Warning (512): SQL Error: 1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'findAll' at line 1 [CORE\cake\libs\model\datasources\dbo_source.php, line 684].
и
Warning (2): Invalid argument supplied for foreach() [APP\views\notes\index.ctp, line 11].
Вот контроллер:
function index(){
$this->set('notes', $this->Note->findAll());
}
function view($id){
$this->Note->id = $id;
$this->set('data', $this->Note->read());
}
function add(){
if (!empty($this->data['Note']))
{
if($this->Note->save($this->data['Note'])){
$this->flash('Your note has been updated.','/notes/');
}
}
}
function edit($id = null){
if (empty($this->data['Note'])){
$this->Note->id = $id;
$this->data = $this->Note->read();
}
else{
if($this->Note->save($this->data['Note']))
{
$this->flash('Your note has been updated.','/notes/');
}
}
}
function delete($id){
if ($this->Note->del($id)){
$this->flash('The note with id: '.$id.' has been deleted.', '/notes');
}
}
}
?>
Вот index.ctp:
<h1>My Notes</h1>
<p>
<?php echo $html->link('Add Note', '/notes/add') ?>
</p>
<table>
<tr>
<th>Id</th>
<th>Title</th>
<th>Created</th>
</tr>
<?php foreach ($notes as $note): ?>
<tr>
<td><?php echo $note['Note']['id']; ?></td>
<td>
<?php echo $html->link($note['Note']['title'], "/notes/view/{$note['Note']['id']}")?>
[<?php echo $html->link('Edit', "/notes/edit/{$note['Note']['id']}")?>,
<?php echo $html->link('Delete', "/notes/delete/{$note['Note']['id']}", null, 'Are you sure?')?>]
</td>
<td><?php echo $note['Note']['created']; ?></td>
</tr>
<?php endforeach; ?>
</table>
А вот файл database.php, который используется:
var $default = array(
'driver' => 'mysql',
'connect' => 'mysql_pconnect',
'host' => 'localhost',
'login' => 'root',
'password' => '',
'database' => 'memo'
);
Весь предоставленный код взят из учебного пособия по http://www.sitepoint.com/application-development-cakephp/.
ВОПРОС: Почемуэто не работает?Я использую Cakephp 1.3.10.
Любая помощь приветствуется.