Fouten in classes
Hallo.
Bootstrap.php
Bootstrap.php
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<?php
class KosLib
{
function __construct()
{
if(!class_exists('Database')){
include_once('/var/www/KosLib/config/database.php');
$this->db = new Database();
}
if(!class_exists('Kenteken')){
include_once('/var/www/KosLib/classes/kenteken.php');
$this->kenteken = new Kenteken();
}
}
}
[/code]
[code=php]
[code]<?php
class Kenteken extends KosLib
{
function __construct()
{
parent::__construct();
}
function getPlateTypes()
{
$sql = 'SELECT
ordernr,
description
FROM
kentekens';
return $this->db->query($sql);
}
}
?>
index.php
[code=php]
<?php
ini_set('display_errors', 1);
include('/var/www/KosLib/bootstrap.php');
$KL = new KosLib;
foreach($KL->kenteken()->getPlateTypes() as $plateType)
{
echo $plateType->description.'<br />';
}
?>
Foutmelding:
[quote]
Fatal error: Call to undefined method KosLib::kenteken() in /var/www/Testhoek/index.php on line 8[/quote]
Ik snap dat er iets fout gaat, en ook wel ongeveer wat er fout gaat, maar, hoe los ik het op en krijg ik het werkend?
class KosLib
{
function __construct()
{
if(!class_exists('Database')){
include_once('/var/www/KosLib/config/database.php');
$this->db = new Database();
}
if(!class_exists('Kenteken')){
include_once('/var/www/KosLib/classes/kenteken.php');
$this->kenteken = new Kenteken();
}
}
}
[/code]
[code=php]
[code]<?php
class Kenteken extends KosLib
{
function __construct()
{
parent::__construct();
}
function getPlateTypes()
{
$sql = 'SELECT
ordernr,
description
FROM
kentekens';
return $this->db->query($sql);
}
}
?>
index.php
[code=php]
<?php
ini_set('display_errors', 1);
include('/var/www/KosLib/bootstrap.php');
$KL = new KosLib;
foreach($KL->kenteken()->getPlateTypes() as $plateType)
{
echo $plateType->description.'<br />';
}
?>
Foutmelding:
[quote]
Fatal error: Call to undefined method KosLib::kenteken() in /var/www/Testhoek/index.php on line 8[/quote]
Ik snap dat er iets fout gaat, en ook wel ongeveer wat er fout gaat, maar, hoe los ik het op en krijg ik het werkend?