/** * Get the Bootstrap static object * * @return self */ public static function getInstance() { if (!isset(self::$_Command)) { self::$_Command = parent::getInstance(); } return self::$_Command; }
/** * Display a listing of the resource. * * @return Response */ public function index() { // Using factory // Getting an instance of a model User example $user = ModelFactory::getInstance('User'); // Getting an instance of a Library String $stringLib = LibraryFactory::getInstance('String'); // Getting an instance of a Filter DateRange $dateRange = FilterFactory::getInstance('DateRange'); // Getting an instance of a Type User $userType = TypeFactory::getInstance('User'); // Perform an access check AccessCheckFactory::getInstance('User')->canAccess(auth()->user()->id, 'view'); // Using facade // Getting an instance of a model User example $user = \Model::getInstance('User'); // Getting an instance of a Library String $stringLib = \Library::getInstance('String'); // Getting an instance of a Filter DateRange $dateRange = \Filter::getInstance('DateRange'); // Getting an instance of a Type User $userType = \Type::getInstance('User'); // Passing data to view example $this->view->fullname = auth()->user()->fullname; // Perform an access check \AccessCheck::getInstance('User')->canAccess(1, 'view'); return $this->view('dashboard'); }
static function retrieve(Criteria $criteria) { if (!self::$DB) { self::$DB = new MySQL(); } $schema = self::getSchema($criteria->from_model_name); $relationships = $schema->getRelationships(); foreach ($relationships as $rel) { $criteria->addJoin($rel->foreignModel, "{$criteria->from_model_name}.{$rel->name}", "{$rel->foreignModel}.{$rel->foreignKey}", Criteria::LEFT_JOIN); } $sql = self::getSelectString($criteria); $rs = self::$DB->query($sql); $model_array = array(); while ($data = self::$DB->fetch($rs)) { $model = Model::getInstance($criteria->from_model_name); self::hydrateModel($model, $data); foreach ($relationships as $relationship) { $foreignModel_name = $relationship->foreignModel; $model->{$foreignModel_name} = Model::getInstance($foreignModel_name); self::hydrateModel($model->{$foreignModel_name}, $data); } $model_array[] = $model; } return $model_array; }
/** * Get the context static object * * @return self */ public static function getInstance() { if (!isset(self::$_Request)) { self::$_Request = parent::getInstance(); } return self::$_Request; }
public function display($tpl = null) { Model::addIncludePath(JPATH_BASE . DIRECTORY_SEPARATOR . 'components' . DIRECTORY_SEPARATOR . 'com_menus' . DIRECTORY_SEPARATOR . 'models'); $model = Model::getInstance('Menus', 'MenusModel'); $this->menutypes = $model->getItems(); $this->menu = JApplication::getInstance('site')->getMenu(); parent::display($tpl); }
public static function getInstance($args = null) { if (!isset($args['class'])) { $args['class'] = 'Logger'; } if (!isset($args['db'])) { $args['db'] = LOG_IRI; } return parent::getInstance($args); }
public static function getInstance($args = null) { if (!isset($args['class'])) { $args['class'] = 'LensModule'; } if (!isset($args['db'])) { $args['db'] = LENS_IRI; } return Model::getInstance($args); }
public function getModel($name = '', $prefix = '', $config = array()) { require_once 'model.php'; if (!$name) { $class = get_class($this); list($_prefix, $name) = explode('View', $class); $prefix = $_prefix . 'Model'; } $model = Model::getInstance($name, $prefix, $config); return $model; }
public function checkUser($username) { $db = Model::getInstance(); $mysqli = $db->getConnection(); $escapedUsername = $mysqli->real_escape_string($username); if ($result = $mysqli->query("SELECT password FROM users WHERE username = '******' LIMIT 1")) { if ($result->num_rows > 0) { return $result; } $result->close(); } }
private function sql() { $stats = Model::getInstance(); $stats = $stats->getStats(); $count = count($stats); $time = 0; if (is_array($stats)) { foreach ($stats as $stat) { $time += $stat['timer']; } } $this->debug .= "<br><div class='catrina-row'>Sql(" . $count . ")" . $time . " сек.</div>"; }
public function __construct($source) { $storage = Model::getInstance(); $this->_token = token_get_all($source); foreach ($this->_token as $key => $value) { if (is_array($value)) { $type = token_name($value[0]); $this->_token[$key][0] = $type; } else { $this->_token[$key] = [0 => 'T_STRUCTURE', 1 => trim($value), 2 => 0]; } } }
public static function getInstance($args = null, $className = null) { if (null === $args) { $args = array(); } if (!isset($args['db'])) { $args['db'] = HEARTBEAT_IRI; } if (null === $className) { $className = 'HeartbeatModel'; } return Model::getInstance($args, $className); }
public function placeOrder($order) { $db = Model::getInstance(); $mysqli = $db->getConnection(); $escapedDepartment = $mysqli->real_escape_string($order->department); $escapedItem = $mysqli->real_escape_string($order->item_no); $escapedSize = $mysqli->real_escape_string($order->size); $escapedColor = $mysqli->real_escape_string($order->color); $sql = "INSERT INTO orders (department, item_no, size, color)\n VALUES ('" . $escapedDepartment . "','" . $escapedItem . "','" . $escapedSize . "','" . $escapedColor . "')"; if ($mysqli->query($sql) === TRUE) { echo "New record created successfully"; } else { echo "Error: " . $sql . "<br>" . $mysqli->error; } }
/** * 初始化 * */ public static function init() { $AlphaSession = new Session(); $AlphaSession->lifeTime = ini_get('session.gc_maxlifetime'); if (Config::get('session_user_LOC') == 'db') { $AlphaSession->handler = Model::getInstance()->db(); } else { $AlphaSession->handler = Model::getInstance()->cache(); } ini_set('session.save_handler', 'user'); session_module_name('user'); session_set_save_handler(array($AlphaSession, 'open'), array($AlphaSession, 'close'), array($AlphaSession, 'read'), array($AlphaSession, 'write'), array($AlphaSession, 'destroy'), array($AlphaSession, 'gc')); ini_get('session.auto_start') || session_start(); //自动开启session,必须在session_set_save_handler后面执行 }
public static function getInstance($args = null, $className = null) { if (null === $args) { $args = array(); } if (!isset($args['db'])) { $args['db'] = MQ_IRI; } if (null === $className) { $className = 'MQModel'; if (!strncmp($args['db'], 'http:', 5) || !strncmp($args['db'], 'https:', 6)) { $className = 'MQHTTPClientModel'; } } return Model::getInstance($args, $className); }
public static function getInstance($args = null, $className = null, $defaultDbIri = null) { if (null === $args) { $args = array(); } if (!isset($args['db'])) { $args['db'] = $defaultDbIri ? $defaultDbIri : CLUSTER_IRI; } if (null === $className) { $className = 'ClusterModel'; if (!strncmp($args['db'], 'file:', 5)) { $className = 'ClusterFileModel'; } } return Model::getInstance($args, $className, null); }
public static function getInstance($args = null, $className = null, $defaultDbIri = null) { return parent::getInstance($args, $className === null ? 'WordPress' : $className, $defaultDbIri === null ? WORDPRESS_IRI : $defaultDbIri); }
public function __construct() { $this->db = parent::getInstance(); }
function __construct() { $this->db = Model::getInstance()->db; }
public static function getInstance($args = null, $className = null, $defaultDbIri = null) { return Model::getInstance($args, $className ? $className : 'ClusterFS', $defaultDbIri ? $defaultDbIri : CLUSTERFS_IRI); }
/** * Initialize the <b>Model</b>. * * Called by the <b>initializeFacade()</b> method. * * Override this method in your subclass of <b>Facade</b> if * one or both of the following are true: * * - You wish to initialize a different <b>Model</b>. * - You have <b>Proxys</b> to register with the <b>Model</b> that do not<br> * retrieve a reference to the <b>Facade</b> at construction time. * * If you don't want to initialize a different <b>Model</b>, * call <b>parent::initializeModel()</b> at the beginning of your * method, then register <b>Proxys</b>. * * <b>Note:</b><br> * This method is <i>rarely</i> overridden; in practice you are more * likely to use a <b>Command</b> to create and register <b>Proxys</b> * with the <b>Model</b>, since <b>Proxys</b> with mutable data will likely * need to send <b>Notifications</b> and thus will likely want to fetch a reference to * the <b>Facade</b> during their construction. * * @return void */ protected function initializeModel() { if (isset($this->model)) { return; } $this->model = Model::getInstance($this->multitonKey); }
public static function getInstance($class = __CLASS__) { return parent::getInstance($class); }
public function __construct() { $this->model = Model::getInstance(); }
/** * Helper para crear titulos de columnas ordenables en los listados. * * attr es el nombre del atributo por la que se va a verficar el orden. * sort es el nombre del atributo por el que se esta ordenando actualmente. * */ public static function orderBy($params) { $model = Model::getInstance(); $sort = $model->get('sort'); // puede ser vacio //$params['sort']; // sort actual $current_dir = $model->get('dir'); // TODO> si hay max y offset, conservarlos. if (!isset($params['attrs'])) { $params['attrs'] = array(); } $dir = 'asc'; if ($sort === $params['attr']) { if ($current_dir === 'asc') { $dir = 'desc'; $params['attrs']['class'] = 'order_desc'; // FIXED> para CSS FIXME: me lo pone como params de la url, no en la tag. } else { $params['attrs']['class'] = 'order_asc'; // FIXED> para CSS FIXME: me lo pone como params de la url, no en la tag. } } //$res .= '<a href="'. Helpers::params2url( array('sort'=>$attr, 'dir'=>$dir) ) .'">'; // TODO: no tengo acceso a los params desde helpers. //$res .= $attr; // TODO: Habria que ver si esto es i18n, deberia haber algun "display name" asociado al nombre del campo. //$res .= '</a>'; // Agregado de params de filtrado a links (http://code.google.com/p/yupp/issues/detail?id=49) $_params = $model->getAll(); // params + lo que metio el controller como model para la view foreach ($_params as $k => $v) { if (String::startsWith($k, 'filter_')) { $params[$k] = $v; } } // Soporte para addParams, la vista puede decirle que otros // params quiere poner en la url (p.e. 'query' si se hizo // una busqueda y se quiere tener ordenamiento por los resultados). if (isset($params['addParams'])) { foreach ($params['addParams'] as $paramName) { $params[$paramName] = $model->get($paramName); // los params se sacan del modelo actual, la vista sabe cuales params quiere } $params['addParams'] = NULL; } // Para mantener el paginado. $params['offset'] = $model->get('offset'); // puede no estar $params['max'] = $model->get('max'); // puede no estar $params['dir'] = $dir; $params['sort'] = $params['attr']; if (!isset($params['body'])) { $params['body'] = $params['attr']; } $res = self::link($params); return $res; }
/** * [__construct description] */ public function __construct() { // Creamos una nueva conexión $this->_db = Model::getInstance(); }
public static function model($name = null) { Lib::load('model'); return Model::getInstance($name); }
public static function getInstance($args = null, $className = null, $defaultDbIri = null) { return Model::getInstance($args, $className ? $className : 'HeartbeatModule', $defaultDbIri ? $defaultDbIri : HEARTBEAT_IRI); }
<?php $m = Model::getInstance(); $users = $m->get('users'); YuppLoader::load('apps.twitter.helpers', 'THelpers'); ?> <html> <layout name="twitter" /> <head> <style type="text/css"> .user-result { width: 150px; display: inline-block; align: left; margin-bottom: 5px; } .user-result img { vertical-align: middle; margin-right: 5px; } </style> </head> <body> <div class="well"> <legend>Search result:</legend> <!-- search result --> <?php foreach ($users as $user) { echo '<div class="user-result">'; // TODO: template para mostrar cada usuario THelpers::gravatar(40, $user);
protected function initializeModel() { if ($this->model != null) { return; } $this->model = Model::getInstance(); }
private static function render($logic_route, $command, $context, $router) { // Configuro el command para la view... // Si la pagina es fisica $pagePath = 'apps/' . $logic_route['app'] . '/views/' . $logic_route['controller'] . '/' . $command->viewName() . '.view.php'; //echo $pagePath . '<br/>'; //Logger::struct($logic_route, 'render logic route'); //Logger::struct($command, 'render command'); //$pagePath = realpath('./'.$pagePath); // Resuelve .. y . // FIXME: en linux puede tener problemas resolviendo . y .. en la path, necesitaria resolverla a la canonica // realpath se desactiva en algunos hostings por temas de seguridad, habria que implementar una alternativa // http://php.net/manual/en/function.realpath.php if (!file_exists($pagePath)) { // Intento resolver path con .. en linux $pagePath = preg_replace('/\\w+\\/\\.\\.\\//', '', $pagePath); // Saca .. pero no saca . y deberia } //echo $pagePath . '<br/>'; //apps/cms2/views/page/../cms/displayPageRO.view.php //apps/cms2/views/cms/displayPageRO.view.php // Si la ruta referenciada no existe, intento mostrar la vista de scafolding correspondiente // a la accion, pero las acciones con vistas dinamicas son solo para acciones: 'show','list','edit','create'. if (!file_exists($pagePath)) { //Logger::getInstance()->log("no existe pagePath $pagePath " . __FILE__); //Logger::getInstance()->log("view name es " . $command->viewName()); // Si puedo mostrar la vista dinamica: if (in_array($command->viewName(), array('show', 'list', 'edit', 'create', 'index', 'appControllers', 'dbStatus'))) { $pagePath = 'core/mvc/view/scaffoldedViews/' . $command->viewName() . '.view.php'; // No puede no existir, es parte del framework! } else { if (is_numeric($command->viewName())) { // FIXME: verificar que existe, porque no se implementaron todos los errores... $pagePath = 'core/mvc/view/error/' . $command->viewName() . '.view.php'; // No puede no existir, es parte del framework! // FIXME: poner un error general por si no esta en la lista $codes = array(403 => 'Forbidden', 404 => 'Not Found', 500 => 'Internal Server Error'); header("HTTP/1.0 " . $command->viewName() . " " . $codes[$command->viewName()]); } else { // Tira 404: Not Found // Sobreescribo el command $command = ViewCommand::display('404', new ArrayObject(array('message' => 'La vista <b>' . $pagePath . '</b> no existe')), new ArrayObject()); $pagePath = 'core/mvc/view/error/404.view.php'; header("HTTP/1.0 404 Not Found"); } } // FIXME: con esto de arriba no es necesario tener mas el "mode". } $command->setPagePath($pagePath); // FIXME: No se usa para nada el pagePath en el command. // Model va a ser accedida desde las vistas. $model = Model::getInstance(); $model->setModel($command->params()); // $command->params() es el modelo devuelto por la accion del controller. $model->addFlash($command->flash()); // Solucion a agregar flash cuando se hace redirect $model->addFlash($router->getFlashParams()); /// ACTUALIZAR CONTEXTO /// $context->setModel($model); //$context->update(); /// ACTUALIZAR CONTEXTO /// $layoutManager = LayoutManager::getInstance(); $layoutManager->renderWithLayout($pagePath); }