Mam sobie taki "szablonik aplikacji", oparty w 100% na obiektach.
(index.php)
<?php
require_once ('../smarty/Smarty-2.6.9/libs/Smarty.class.php');
require_once ('bd.klasa.php');
$bd = bd::wybierz ('MySQL', 'localhost', 'root', '', 'testy');
$dane_bd = $bd -> zapytanie ('SHOW TABLES');
$smarty = new Smarty;
$smarty -> template_dir = 'szablony';
$smarty -> compile_dir = 'szablony';
$smarty -> assign ('ZAWARTOSC', $dane_bd);
$smarty -> display ('szablon.test.tpl');
?>
(bd.klasa.php)
<?php
class bd {
private function __construct () {}
static public function wybierz
($typ, $host, $uzytkownik, $haslo, $baza) { require_once ('bd-' . $typ . '.klasa.php');
self::$instancja = new $typ ($host, $uzytkownik, $haslo, $baza);
return self::$instancja;
}
}
?>
(bd-MySQL.klasa.php)
<?php
private $uchwyt;
public $zapytanie;
function __construct ($host, $uzytkownik, $haslo, $baza) {
return $this->uchwyt;
}
function zapytanie ($zapytanie) {
return $this->zapytanie;
}
}
?>
Ten kod w wyniku wyświetla "Resource id #6" (w index.php). Dlaczego i jak temu zaradzić?
Pozdrawiam, Fipaj