Пока работает выборка данных. Сохранение не пробовал.
This commit is contained in:
parent
742bd12d1b
commit
39de8ae0a1
|
|
@ -8,8 +8,9 @@ class Model
|
|||
private $_id_;
|
||||
private $_vals_ = array();
|
||||
|
||||
function __construct()
|
||||
function __construct($table)
|
||||
{
|
||||
$this->_tableName_ = $table;
|
||||
$this->_primaryKey_ = $this->getPk();
|
||||
}
|
||||
|
||||
|
|
@ -45,7 +46,13 @@ class Model
|
|||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
static function getByPrimaryKey($id)
|
||||
{
|
||||
$instance = new self();
|
||||
return $instance->getByPK($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Возвращает массив с ассоциативными массивами, соответствующими записями в БД.
|
||||
* @param string $where просто строка с условиями: (`id` > 1) AND (`name` == 'TEST')
|
||||
* @param string $order строка с именем толбца и напрабления: `summ` DESC
|
||||
|
|
@ -62,8 +69,8 @@ class Model
|
|||
|
||||
$this->_id_ = NULL; // Это больше не конкретная запись
|
||||
$ready = array();
|
||||
|
||||
while ($row = $res->fetch(PDO::FETCH_ASSOC))
|
||||
//print_r($res);die;
|
||||
while ($res && $row = $res->fetch(PDO::FETCH_ASSOC))
|
||||
{
|
||||
$ready[$row[$this->_primaryKey_]] = $row;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ class IndexController extends Controller
|
|||
if (!App::$user )
|
||||
self::addScript('//ulogin.ru/js/ulogin.js');
|
||||
|
||||
$category = new Category();
|
||||
$category = Category::model()->getAll();
|
||||
|
||||
$routes = array();
|
||||
if (App::$user)
|
||||
|
|
@ -69,7 +69,7 @@ class IndexController extends Controller
|
|||
$og['url'] = 'http://wikipoints.ru/?point='.$id;
|
||||
$og['image'] = $point->img;
|
||||
}
|
||||
else if($_GET['point'] && strtolower($_GET['point']) == 'random')
|
||||
else if(isset($_GET['point']) && $_GET['point'] && strtolower($_GET['point']) == 'random')
|
||||
{
|
||||
$og['title'] = 'Случайная точка на wikipoints.ru';
|
||||
$og['description'] = 'Загляните сюда: http://vk.com/wikipoints Случайная точка на карте - лучший способ узнать что-то новое!';
|
||||
|
|
@ -80,7 +80,7 @@ class IndexController extends Controller
|
|||
}
|
||||
|
||||
self::render('indexTemplate.php', array(
|
||||
'categories' => $category->getAll('', 'ord'),
|
||||
'categories' => $category,
|
||||
'user' => App::$user,
|
||||
'routes' => $routes,
|
||||
'og' => $og,
|
||||
|
|
|
|||
|
|
@ -8,11 +8,8 @@ class JsonController extends Controller
|
|||
*/
|
||||
static function actionPoints()
|
||||
{
|
||||
$points = new Point();
|
||||
$points = $points->getAll();
|
||||
|
||||
$categories = new Category();
|
||||
$categories = $categories->getAll();
|
||||
$points = Point::model()->getAll();
|
||||
$categories = Category::model()->getAll();
|
||||
|
||||
$result = array();
|
||||
|
||||
|
|
@ -38,13 +35,34 @@ class JsonController extends Controller
|
|||
$id = (int) App::getParam('id');
|
||||
if ($id)
|
||||
{
|
||||
$point = new Point();
|
||||
$point = $point->getByPK($id);
|
||||
//$point = Point::getByPrimaryKey($id);
|
||||
//$point = $point->getByPK($id);
|
||||
|
||||
// $point = new Point();
|
||||
// $point->name = 'TEST';
|
||||
// $point->lat = 12;
|
||||
// $point->lng = 44;
|
||||
// $point->img = 'sdfsdfsdf';
|
||||
// $point->description = 'sdfsdfsdfsdfsdfsdfsdfsfd';
|
||||
// $point->categoryId = 1;
|
||||
// $point->source = '';
|
||||
// $point->author = 2;
|
||||
// $point->date = time();
|
||||
//
|
||||
// print_r($point->save());
|
||||
//
|
||||
// print '<br/><br/><br/><br/>';
|
||||
//
|
||||
//
|
||||
// print_r($point);
|
||||
// die;
|
||||
|
||||
$point = Point::model()->getByPK($id);
|
||||
|
||||
$point->descriptionHtml = nl2br($point->description);
|
||||
$point->name = htmlspecialchars($point->name);
|
||||
|
||||
$categories = new Category();
|
||||
$categories = $categories->getAll();
|
||||
$categories = Category::model()->getAll();
|
||||
|
||||
$point->categoryIcon = $categories[$point->categoryId]['icon'];
|
||||
$point->categoryName = $categories[$point->categoryId]['name'];
|
||||
|
|
@ -61,8 +79,7 @@ class JsonController extends Controller
|
|||
*/
|
||||
static function actionCategories()
|
||||
{
|
||||
$categories = new Category();
|
||||
$categories = $categories->getAll();
|
||||
$categories = Category::model()->getAll();
|
||||
|
||||
self::renderPartial('json.php', array(
|
||||
'data' => $categories,
|
||||
|
|
|
|||
|
|
@ -4,10 +4,12 @@ class Category extends Model
|
|||
{
|
||||
function __construct()
|
||||
{
|
||||
|
||||
$this->_tableName_ = 'categories';
|
||||
parent::__construct();
|
||||
return self::model();
|
||||
}
|
||||
|
||||
static function model()
|
||||
{
|
||||
return new Model('categories');
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -4,10 +4,12 @@ class Point extends Model
|
|||
{
|
||||
function __construct()
|
||||
{
|
||||
|
||||
$this->_tableName_ = 'points';
|
||||
parent::__construct();
|
||||
return self::model();
|
||||
}
|
||||
|
||||
static function model()
|
||||
{
|
||||
return new Model('points');
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue