Reputation: 4747
I have a Problem with cakePHP.
This is my Model:
<?php
class Veranstaltung extends AppModel
{
var $name = 'Veranstaltung';
var $useTable = 'veranstaltungen';
}
?>
and this is my Controller:
<?php
class VeranstaltungenController extends AppController
{
var $name = 'Veranstaltungen';
public function index()
{
$this->set('veranstaltungen',$this->Veranstaltung->find('all'));
}
}
?>
but $this->Veranstaltung
Returns null.
How do I solve this?
Upvotes: 1
Views: 98
Reputation: 426
<?php
class VeranstaltungenController extends AppController
var $uses = array('Veranstaltungen');
public function index()
{
$this->set('veranstaltungen',$this->Veranstaltung->find('all'));
}
}
?>
Try in your controller
Upvotes: 0
Reputation: 3337
You forget to include your model in controller. Do do this add $uses
field in your controller which is type of array
:
class VeranstaltungenController extends AppController
{
public $uses = array('Veranstaltung');
public function index()
{
$this->set('veranstaltungen',$this->Veranstaltung->find('all'));
}
}
If there still be a problem it could be required to use
App::uses('Veranstaltung', 'Model');
before your controller class definition.
And please forget about var
keyboard, because it's only for backward compatibility with PHP4.
In order to maintain backward compatibility with PHP 4, PHP 5 will still accept the use of the keyword
var
in property declarations instead of (or in addition to)public
,protected
, orprivate
. However, var is no longer required. In versions of PHP from 5.0 to 5.1.3, the use ofvar
was considered deprecated and would issue anE_STRICT
warning, but since PHP 5.1.3 it is no longer deprecated and does not issue the warning.
Upvotes: 2
Reputation: 4776
You don't need var $name = 'Veranstaltungen';
in your controller.
Also make sure you have configured your database properly?
Then try this:
$this->loadModel("Veranstaltungen");
$this->set('veranstaltungen',$this->Veranstaltung->find('all'));
Upvotes: 0