/** * Save and Get data into a database * @Route /new/example/persisting * */ public function persistingAction() { /** * $this->getStoreManager() is a shortcut of $this->getStore()->getManagerManager() and can be * accesed like this $this->app->getStore()->getManager() * * We need to check if the persona table exist and create it if not exist [this is only for examples purposes] */ if (!$this->getStoreManager()->getConnection()->getSchemaManager()->tablesExist(array('persona'))) { $this->getStore()->generateSchema('exampleBundle', array('Persona')); } /** * Save a Person entity * */ $persona = new \examples\exampleBundle\Model\Entity\Persona(); $persona->setNombre('Liams'); $persona->setApellidos('Adam'); $persona->setSexo(true); $persona->setEdad(25); $this->getStoreManager()->persist($persona); $this->getStoreManager()->flush(); /** * Accessing to the previusly save entity * and return an array of results * exampleBundle:Persona is the alias for \examples\exampleBundle\Model\Entity\Persona */ $list = new \Raptor\Util\ItemList($this->getStoreManager()->getRepository('exampleBundle:Persona')->findAll()); return $list->toJson(); }
/** * Render response body * @param array $env * @param \Exception $exception * @return string */ protected function renderGeneric(&$env, $exception) { $title = 'Ups something was wrong !!'; $html = sprintf('<div style="background-color: #402878 ;color: white;padding: 25px;width:100%s"><h1>%s</h1></div>', "%", $title); $html .= '<div style="background:gray;color:white;margin-top:0;padding:25px;overflow-x:scroll;width:100%">'; $html .= '<p>Please go to your administrator</p>'; $html .= '</div>'; if ($this->app->request()->isXhr()) { $this->app->contentType(\Raptor\Raptor::JSON); $response = new \Raptor\Util\ItemList(); $response->set('cod', 5); $response->set('msg', '<h2>Ups something was wrong !!</h2>'); return $response->toJson(); } return sprintf("<html><head><title>%s</title><style>body{margin:0;padding:30px;font:12px/1.5 Helvetica,Arial,Verdana,sans-serif;}h1{margin:0;font-size:48px;font-weight:normal;line-height:48px;}strong{display:inline-block;width:65px;}</style></head><body>%s</body></html>", $title, $html); }
* * @author William Amed <*****@*****.**>, Otto Haus <*****@*****.**> * @copyright 2014 * @link http://dinobyte.net * @version 2.0.1 * @package Raptor * * MIT LICENSE * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the * "Software"), to deal in the Software without restriction, including * without limitation the rights to use, copy, modify, merge, publish, * distribute, sublicense, and/or sell copies of the Software, and to * permit persons to whom the Software is furnished to do so, subject to * the following conditions: * * The above copyright notice and this permission notice shall be * included in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ $data = new \Raptor\Util\ItemList(\Raptor\Raptor::getInstance()->getStore()->getManager()->getRepository('exampleBundle:Persona')->findAll()); file_put_contents(__DIR__ . '/mas', $data->toJson());
/** * Default Error handler */ protected function defaultError($e) { $this->getLog()->error($e); if ($this->request()->isXhr()) { $this->contentType(\Raptor\Raptor::JSON); $response = new \Raptor\Util\ItemList(); $response->set('cod', 5); $response->set('msg', "<h2>Error</h2>" . '<h4>A website error has occurred. The website administrator has been notified of the issue. Sorry for the temporary inconvenience.</h4>'); echo $response->toJson(); return; } echo self::generateTemplateMarkup('Error', '<p>A website error has occurred. The website administrator has been notified of the issue. Sorry for the temporary inconvenience.</p>'); }