Esempio n. 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);
 }
Esempio n. 2
0
 public function testSetTemplatesDirectory()
 {
     $view = new \Slim\View();
     $view->setTemplatesDirectory('templates/');
     // <-- Should strip trailing slash
     $this->assertAttributeEquals('templates', 'templatesDirectory', $view);
 }
Esempio n. 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);
 }
Esempio n. 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));
 }
Esempio n. 5
-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));
 }