static function model($id) { $modelname = get_called_class(); $item = App::gi()->db->query('select * from ' . $modelname::$table . ' where ' . $modelname::$primary . '=' . App::gi()->db->_($id))->row(); $model = new $modelname(); $model->__attributes = $item; return $model; }
function actionPlay() { $id = App::gi()->uri->id; $game = new Game(); if ($id > 0) { if ($game->verifyQuestion($id)) { $model = $game->get_question_by_id($id); } else { header('Location: /game/'); } } else { header('Location: /game/'); } $this->render('play', array('model' => $model)); }
public static function verifyQuestion($id) { $user_id = $_SESSION['id']; $answer = App::gi()->db->items('#__user_answers', "user_id={$user_id}"); if (count($answer) > 0) { foreach ($answer as $key => $value) { if ($value['done'] == '0' && $value['question_id'] == $id) { return true; } elseif ($value['done'] == '1' && $value['question_id'] == $id) { return false; } } return $answer; } else { return true; } }
<?php session_start(); define('ROOT', dirname(__FILE__) . '/'); define('IDEAL', dirname(__FILE__) . '/ideal/'); define('APP', dirname(__FILE__) . '/application/'); define('CONFIG', dirname(__FILE__) . '/ideal/config/'); define('DATABASES', dirname(__FILE__) . '/ideal/databases/'); define('USER_IMAGES', dirname(__FILE__) . '/assets/images/users/'); include IDEAL . 'framework.php'; App::gi()->start();
<form action="/post/<?php echo App::gi()->uri->action; ?> " method="post"> <div class="form-group"> <label for="name">Название</label> <input type="text" class="form-control" id="name" name="form[name]" placeholder="Введите название поста" value="<?php echo htmlspecialchars($item->name); ?> "> </div> <div class="form-group"> <label for="content">Текст</label> <textarea type="password" class="form-control" name="form[content]" id="content"><?php echo htmlspecialchars($item->content); ?> </textarea> </div> <input type="hidden" name="form[id]" value="<?php echo intval($item->id); ?> "> <button type="submit" class="btn btn-default"><?php echo $item->id ? 'Сохранить' : 'Создать'; ?> </button> </form>
function __construct() { $this->_data = new stdClass(); $this->db = App::gi()->db; }