public static function instance() { if (self::$instance == NULL) { self::$instance = new AdsStore(); } return self::$instance; }
header("Content-Type: text/html; charset=utf-8"); $project_root = $_SERVER['DOCUMENT_ROOT']; $smarty_dir = $project_root . '/Smarty/'; require_once "connect_to_db.php"; //подключаемся к самой БД require_once "bd_script.php"; //подключаем файл со скриптами для БД // подключаем smarty $smarty_dir = 'Smarty/'; require $smarty_dir . 'libs/Smarty.class.php'; $smarty = new Smarty(); $smarty->compile_check = TRUE; $smarty->debugging = 0; $smarty->template_dir = $smarty_dir . 'templates/'; $smarty->compile_dir = $smarty_dir . 'templates_c/'; $smarty->cache_dir = $smarty_dir . 'cache/'; $smarty->config_dir = $smarty_dir . 'configs/'; //Подключаем классы spl_autoload_register(function ($class) { $class_path = 'lib/' . $class . '.class.php'; if (file_exists($class_path)) { require_once $class_path; } }); $adsStore = AdsStore::instance(); $adsStore->getAllAdsFromDb(); $errors = new errors(array('title', 'description', 'price', 'seller_name', 'phone')); //передаем 'имя переменной' и 'значение' $smarty->assign('title', 'Наше объявление'); $smarty->assign('city', $adsStore->getlocationid()); $smarty->assign('category', $adsStore->getCategories());
<?php require_once "prepare.php"; AdsStore::instance()->getAllAdsFromDb()->prepareForOut()->display();
public static function getInstance() { // Создаем экземпляр AdsStore if (self::$instance == NULL) { self::$instance = new AdsStore(); } return self::$instance; }
$firePHP->log($tube_stations, '$tube_stations'); $category_id = ''; $result = $db->select('select * from categories order by id ASC'); $firePHP->log($result, 'categories $result'); foreach ($result as $value) { $result2 = $db->select('select * from subcategories where category=' . $value['id'] . ' order by subcategory'); $firePHP->log($result2, 'subcategories $result2'); foreach ($result2 as $value2) { $subcategory[$value2['subcategory']] = $value2['id']; } $categories[$value['category']] = $subcategory; $subcategory = array(); } $firePHP->log($categories, '$categories'); // если гет заполнен, значит запросили изменение (в ходе просмотра) и удаление $main = AdsStore::instance(); $main->getAllAdsFromDb(); $main->writeOutAll(); if ($_POST['form'] == "Сохранить объявление") { // сохранить элемент // записать изменение в базу //$temp_array = $Ads1->change_ad($db, $_POST, $_GET["id"]); //$firePHP->log($temp_array, 'ads $temp_array'); $main->change_Ad($_GET['id']); $_POST = null; header('Location:' . $site_dir . '/' . $current_php_script . '.php'); } if ($_POST['form'] == "Назад") { $_POST = null; unset($_GET); header('Location:' . $site_dir . '/' . $current_php_script . '.php');
<?php require_once "prepare.php"; if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'delete' && isset($_REQUEST['id'])) { // Кнопка "удалить" нажата? AdsStore::instance()->deleteAds($_REQUEST['id']); echo 'Объявление успешно удалено'; }
<?php require_once "prepare.php"; $adStore = AdsStore::instance()->getAllAdsFromDb(); if (isset($_POST['seller_name']) and isset($_POST['price'])) { // Кнопка 'Отправить' нажата? if ($_POST['private']) { $ad = new AdsCompany($_POST); } else { $ad = new AdsPrivatePerson($_POST); } $CheckResult = AdChecker::check($ad); if ($CheckResult) { // Проверка на заполнение полей $adStore->prepareForOut($ad, $CheckResult); // Если не пройдена - на корректировку } else { $ad->save(); // Иначе - сохранение $adStore->getAllAdsFromDb()->prepareForOut(); } } elseif (isset($_GET['id'])) { // Ссылка на объявление нажата? $adStore->prepareForOut($_GET['id']); } else { // Ничего не нажато - значит новое объявление $adStore->prepareForOut(); } $adStore->display();