1
我前幾天用FlightPHP開始了。現在我創建了我自己的模型imagePreviewModel
。FlightPHP註冊一個類之後找不到方法
這裏是模型:
<?php
class imagePreviewModel{
private $db;
public function __construct(PDO $db){
$this->db = $db;
}
public function getAllImages(){
return $this->db->query('SELECT * FROM images');
}
}
?>
裏面的控制器我註冊的類和調用的方法getAllImages()
。現在,我打開頁面瀏覽器,並得到一個錯誤:調用未定義的方法PDO :: getAllImages()(0)
這裏是控制器的代碼:
<?php
require 'flight/Flight.php';
include 'private/models/imagePreviewModel.php';
Flight::route('/', function(){
Flight::register('imagePreviewModel', 'PDO', array('mysql:host=localhost;dnbname=share','root',''));
$imagePreviewModel = Flight::imagePreviewModel();
$List = $imagePreviewModel->getAllImages();
Flight::render('general', NULL);
});
Flight::start();
?>
誰能幫助我?
我想我發現了這個問題。我註冊了類PDO
,但我想註冊一個名爲'imagePreviewModel'的類。我怎樣才能註冊該課程? 在FlightPHP頁面下面這個例子:
// Register your class
Flight::register('user', 'User');
// Get an instance of your class
$user = Flight::user();
但是,什麼是類名和參數?爲什麼寫了兩次用戶?我需要一點解釋。