Example #1
0
 public function render($name = null, $data = array(), $status = null)
 {
     $contentView = new \Slim\View();
     $data = array_merge($data, (array) $this->templateData);
     if (isset($this->environment['slim.flash'])) {
         $contentView->setData('flash', $this->environment['slim.flash']);
         $this->templateData->flash = $this->environment['slim.flash'];
     }
     $contentView->setTemplatesDirectory($this->appRoot() . '/views');
     $contentView->appendData((array) $this->templateData);
     $contentView->appendData($data);
     if ($name !== null) {
         $this->templateData->content = $contentView->fetch(rtrim($name, '.php') . '.php');
     } else {
         $this->templateData->content = '';
     }
     // Call before render
     if (method_exists($this, 'beforeRender') && !$this->beforeRenderCalled) {
         $this->beforeRender();
     }
     parent::render('template-' . rtrim($this->template, '.php') . '.php', (array) $this->templateData, $status);
 }
Example #2
0
 public function testSetTemplatesDirectory()
 {
     $view = new \Slim\View();
     $view->setTemplatesDirectory('templates/');
     // <-- Should strip trailing slash
     $this->assertAttributeEquals('templates', 'templatesDirectory', $view);
 }
Example #3
0
 public function testSetTemplatesDirectory()
 {
     $view = new \Slim\View();
     $directory = 'templates' . DIRECTORY_SEPARATOR;
     $view->setTemplatesDirectory($directory);
     // <-- Should strip trailing slash
     $this->assertAttributeEquals('templates', 'templatesDirectory', $view);
 }
Example #4
0
 public static function send_mail($msg, $data = array())
 {
     global $config, $app;
     $app = \Slim\Slim::getInstance();
     $mode = $app->getMode();
     $mandrill = new Mandrill($config[$mode]['mandrill_apikey']);
     if (!is_array($msg)) {
         parse_str($msg, $msg);
     }
     foreach (array('text', 'html') as $t) {
         if (!empty($msg[$t]) && strpos(trim($msg[$t]), 'slim:') === 0) {
             $view = new \Slim\View();
             $view->appendData($data);
             $view->setTemplatesDirectory($app->config('templates.path'));
             $msg[$t] = $view->fetch('email/' . substr(trim($msg[$t]), 5));
         }
     }
     //        if (isset($msg['from'])) {
     //            $msg['from_email'] = $msg['from'];
     //            unset($msg['from']);
     //        }
     if (!is_array($msg['to'])) {
         $msg['to'] = array(array('email' => $msg['to']));
     }
     return $mandrill->call('/messages/send', array('message' => $msg));
 }
Example #5
0
 protected function defaultError($e)
 {
     $this->status(500);
     $view = new \Slim\View($this->config('templates.path'));
     $view->display('error/500.php');
     echo $e->xdebug_message;
     //parent::defaultError($e);
     //
     if ($e instanceof \Exception) {
         $code = $e->getCode();
         $message = $e->getMessage();
         $file = $e->getFile();
         $line = $e->getLine();
         $trace = str_replace(array('#', '\\n'), array('<div>#', '</div>'), $e->getTraceAsString());
         $text = $code . "\n" . $message . "\n" . "{$file} :: {$line}\n" . $trace;
         $file = LOGS_DIR . '/error_app.log';
         file_put_contents($file, $text, FILE_APPEND);
     }
 }
Example #6
-1
 function send($msg = '', $data = array())
 {
     global $app;
     $mandrill = new Mandrill(config('mandrill.apikey'));
     if (!is_array($msg)) {
         parse_str($msg, $msg);
     }
     foreach (array('text', 'html') as $t) {
         if (!empty($msg[$t]) && strpos(trim($msg[$t]), 'slim:') === 0) {
             $view = new \Slim\View();
             $view->appendData($data);
             $view->setTemplatesDirectory($app->config('templates.path'));
             $msg[$t] = $view->fetch('email/' . substr(trim($msg[$t]), 5));
         }
     }
     if (isset($msg['from'])) {
         $msg['from_email'] = $msg['from'];
         unset($msg['from']);
     }
     if (!is_array($msg['to'])) {
         $msg['to'] = array(array('email' => $msg['to']));
     }
     return $mandrill->call('/messages/send', array('message' => $msg));
 }