/** * @param array $attributes * @param array $whiteList * * @return boolean * @throws \Phalcon\Mvc\Model\Exception */ private function makeRoot($attributes, $whiteList) { $owner = $this->getOwner(); $owner->{$this->leftAttribute} = 1; $owner->{$this->rightAttribute} = 2; $owner->{$this->levelAttribute} = 1; if ($this->hasManyRoots) { $this->db->begin(); $this->ignoreEvent = true; if ($owner->create($attributes, $whiteList) == false) { $this->db->rollback(); $this->ignoreEvent = false; return false; } $pk = $owner->{$this->rootAttribute} = $owner->{$this->primaryKey}; $owner::findFirst($pk)->update(array($this->rootAttribute => $pk)); $this->ignoreEvent = false; $this->db->commit(); } else { if (count($owner->roots())) { throw new \Phalcon\Mvc\Model\Exception('Cannot create more than one root in single root mode.'); } if ($owner->create($attributes, $whiteList) == false) { return false; } } return true; }
public function _loadFromDatabase($fileId) { $fileinfo = DbAdapter::loadFileInfo($fileId); $this->_filepath = $fileinfo['path']; $this->_filesize = $fileinfo['size']; $this->_filename = $fileinfo['name']; }
/** * Deletes a model from the db * * @param BaseDomainModel $model * @return Mapper */ public function delete(BaseDomainModel $model) { list($whereCondition, $bindings) = $this->getIdentityCondition($model->__identity()); $this->db->delete($this->tableName, $whereCondition, $bindings); return $this; }
* Register a user component */ $di->set('elements', function () { return new Elements(); }); $di->set('crypt', function () { $crypt = new Phalcon\Crypt(); $crypt->setKey('#1dj8$=dp#$%^&df('); //Use your own key! return $crypt; }); $di->set('dbShop', function () use($di, $config) { $eventsManager = new \Phalcon\Events\Manager(); //Get a shared instance of the DbProfiler $profiler = $di->getProfiler(); //Listen all the database events $eventsManager->attach('db', function ($event, $connection) use($profiler) { if ($event->getType() == 'beforeQuery') { $profiler->startProfile($connection->getSQLStatement()); } if ($event->getType() == 'afterQuery') { $profiler->stopProfile(); } }); $connection = new DbAdapter(array('host' => $config->database->host, 'username' => $config->database->username, 'password' => $config->database->password, 'dbname' => $config->database->name)); $connection->setEventsManager($eventsManager); return $connection; }, true); $di->set('profiler', function () { return new \Phalcon\Db\Profiler(); }, true);