Вот недавно начал изучать ОО, и еще не очень все понимаю как реализовать.
Для начал чтоб проверить как усвоился материал параллельно делал новостную ленту.
Так вот, меньше слов больше к теме вопроса.
Вот сам мой пример):
news.php
PHP:
скопировать код в буфер обмена
скопировать код в буфер обмена
- <?PHP
- include "config.php";
- class News
- {
- public $idnews; // Індитифікатор новини
- public $idrybruka; // Індитифікатор рубрики
- public $iduser; // Індитифікатор автора
- public $title; // Заголовок
- public $text; // Текст
- public $date; // Дата private
- function __construct($idnews, $idrybruka, $iduser, $title, $text, $date)
- {
- $this->idnews = $idnews;
- $this->idrybruka = $idrybruka;
- $this->iduser = $iduser;
- $this->title = $title;
- $this->text = $text;
- $this->date = $date;
- }
- }
- class NewsBD
- {
- private $outPut;
- function __construct()
- {
- }
- function Select($news_id = False)
- {
- $sql = "SELECT `idnews`, `idrybruka`, `iduser`, `title`, `min_text`, `max_text`, `date` FROM `news` WHERE `active`='1'";
- ($news_id) ? $sql.= "AND `idnews`='{$news_id}'" : $sql.= "ORDER BY `idnews` DESC";
- {
- ($news_id) ? $opus = $row['max_text'] : $opus = $row['min_text'];
- $outPut[] = new News($row['idnews'], $row['idrybruka'], $row['iduser'], $row['title'], $opus, $row['date']);
- }
- return $outPut;
- }
- }
- ?>