/** * Return the views output * * @return string The output of the view */ public function render() { $rows = ''; $columns = array(); $rowset = $this->getModel()->getRowset(); // Get the columns foreach ($rowset as $row) { $data = $row->toArray(); $columns = array_merge($columns + array_flip(array_keys($data))); } // Empty the column values foreach ($columns as $key => $value) { $columns[$key] = ''; } //Create the rows foreach ($rowset as $row) { $data = $row->toArray(); $data = array_merge($columns, $data); $rows .= $this->_arrayToString(array_values($data)) . $this->eol; } // Create the header $header = $this->_arrayToString(array_keys($columns)) . $this->eol; // Set the content $this->setContent($header . $rows); return parent::render(); }
/** * Transfer the process to other action or controller * * @param string $action Action key you want to transfer * @param string $controller Controller key you want to transfer * @return void */ public function transfer($action, $controller = null) { if ($controller != null) { $this->view->setRenderingController($controller); } $this->view->setRenderingAction($action); $actionMethod = NameManager::convertActionToMethod($action); if ($controller == null) { $this->{$actionMethod}(); } else { $subdir = ''; $parts = explode('/', trim($controller, '/')); $partsCnt = count($parts); if ($partsCnt > 1) { $controller = $parts[$partsCnt - 1]; unset($parts[$partsCnt - 1]); $subdir = implode('/', $parts); } $className = NameManager::convertControllerToClass($controller); $ins = Loader::getControllerInstance($className, $subdir); $ins->setRequest($this->request); $ins->setView($this->view); $ins->{$actionMethod}(); } $this->dispatched = true; }
public function __construct($path) { parent::__construct(); try { $this->_setFile($path); } catch (\Exception $e) { die($e->getMessage()); } }
/** * Return the views output * * @return string The output of the view */ public function render() { //Render the vcard $data = 'BEGIN:VCARD'; $data .= "\r\n"; $data .= 'VERSION:2.1'; $data .= "\r\n"; foreach ($this->_properties as $key => $value) { $data .= "{$key}:{$value}"; $data .= "\r\n"; } $data .= 'REV:' . date('Y-m-d') . 'T' . date('H:i:s') . 'Z'; $data .= "\r\n"; $data .= 'END:VCARD'; $data .= "\r\n"; $this->setContent($data); parent::render(); }
/** * apply curry.ini settings * * @return boolean */ public function applyConfig() { Loader::load('Ini', 'core'); Loader::load('Db', 'db'); $ini = false; if ($this->_appEnv == null) { // Default section is "product" $ini = Ini::load('database.ini', 'product'); } else { $ini = Ini::load('database.ini', $this->_appEnv); } if ($ini === false) { // For the compatibility of a old version. $ini = Ini::load('database.ini', 'connection'); } if ($ini !== false) { Db::setConfig($ini); } $ini = Ini::load('curry.ini'); if ($ini === false) { return false; } if (array_key_exists('dispatch', $ini)) { $values = $ini['dispatch']; $key = 'plugin_enabled'; if (array_key_exists($key, $values)) { if (is_numeric($values[$key]) && $values[$key] == 1) { $this->dispatcher->enablePlugin(true); } } $key = 'is_send_404'; if (array_key_exists($key, $values)) { if (is_numeric($values[$key]) && $values[$key] != 1) { $this->dispatcher->isSend404(false); } } $key = 'sub_controller_enabled'; if (array_key_exists($key, $values)) { if (is_numeric($values[$key]) && $values[$key] == 1) { $this->router->enableSubController(true); } } $key = 'is_rewrite'; if (array_key_exists($key, $values)) { if (is_numeric($values[$key]) && $values[$key] != 1) { $this->router->isRewrite(false); } } $key = 'default_controller'; if (array_key_exists($key, $values)) { $this->router->setDefaultController($values[$key]); } $key = 'default_action'; if (array_key_exists($key, $values)) { $this->router->setDefaultAction($values[$key]); } $key = 'controller_query_key'; if (array_key_exists($key, $values)) { $this->router->setControllerQueryKey($values[$key]); } $key = 'action_query_key'; if (array_key_exists($key, $values)) { $this->router->setActionQueryKey($values[$key]); } $key = 'controller_suffix'; if (array_key_exists($key, $values)) { NameManager::setControllerSuffix($values[$key]); } $key = 'action_suffix'; if (array_key_exists($key, $values)) { NameManager::setActionSuffix($values[$key]); } } if (array_key_exists('view', $ini)) { $values = $ini['view']; $key = 'class_name'; if (array_key_exists($key, $values)) { $this->dispatcher->setViewClass($values[$key]); } $key = 'layout_enabled'; if (array_key_exists($key, $values)) { if (is_numeric($values[$key]) && $values[$key] != 1) { ViewAbstract::setDefaultLayoutEnabled(false); } } $key = 'template_extension'; if (array_key_exists($key, $values)) { NameManager::setTemplateExtension($values[$key]); } } if (array_key_exists('request', $ini)) { $values = $ini['request']; $key = 'auto_trim'; if (array_key_exists($key, $values)) { if (is_numeric($values[$key]) && $values[$key] == 1) { Request::setAutoTrim(true); } } } if (array_key_exists('database', $ini)) { $values = $ini['database']; $key = 'is_singleton'; if (array_key_exists($key, $values)) { if (is_numeric($values[$key]) && $values[$key] == 0) { Db::setIsSingleton(false); } } } if (array_key_exists('logger', $ini)) { Loader::load('Logger', 'utility'); $values = $ini['logger']; $key = 'system_log'; if (array_key_exists($key, $values)) { Logger::setLogName($values[$key]); } $key = 'query_log'; if (array_key_exists($key, $values)) { Logger::setLogName($values[$key], 'query'); Db::enableLogging('query'); } $key = 'output_level'; if (array_key_exists($key, $values)) { $val = strtolower(trim($values[$key])); if (is_numeric($val) == false) { $levels = array('debug' => LogLevel::DEBUG, 'info' => LogLevel::INFO, 'warn' => LogLevel::WARN, 'error' => LogLevel::ERROR, 'except' => LogLevel::EXCEPT); if (array_key_exists($val, $levels)) { $val = $levels[$val]; } else { $val = LogLevel::NO_OUTPUT; } } Logger::setOutputLevel($val, 'query'); } $key = 'max_line'; if (array_key_exists($key, $values)) { Logger::setMaxLine($values[$key]); } $key = 'max_generation'; if (array_key_exists($key, $values)) { Logger::setGeneration($values[$key]); } } if (array_key_exists('loader', $ini)) { $values = $ini['loader']; $key = 'autoload_dirs'; if (array_key_exists($key, $values)) { $dirs = explode(',', $values[$key]); Loader::addAutoloadDirectory($dirs); } } return true; }
/** * Get a route based on a full or partial query string. * * This function force the route to be not fully qualified and not escaped * * @param string $route The query string used to create the route * @param boolean $fqr If TRUE create a fully qualified route. Default FALSE. * @param boolean $escape If TRUE escapes the route for xml compliance. Default FALSE. * @return string The route */ public function getRoute($route = '', $fqr = null, $escape = null) { //If not set force to false if ($escape === null) { $escape = false; } return parent::getRoute($route, $fqr, $escape); }
/** * Initializes the options for the object * * Called from {@link __construct()} as a first step of object instantiation. * * @param ObjectConfig $config An optional ObjectConfig object with configuration options * @return void */ protected function _initialize(ObjectConfig $config) { $count = count($this->getIdentifier()->path); $config->append(array('path' => '', 'filename' => $this->getIdentifier()->path[$count - 1] . '.' . $this->getIdentifier()->name, 'disposition' => 'attachment', 'transport' => 'php')); parent::_initialize($config); }
/** * Clear all assigned values * * @return void */ public function clearValues() { parent::clearValues(); $this->_smarty->clearAllAssign(); }
/** * Supports a simple form of Fluent Interfaces. Allows you to assign variables to the view by using the variable * name as the method name. If the method name is a setter method the setter will be called instead. * * For example : $view->layout('foo')->title('name')->render(). * * @param string $method Method name * @param array $args Array containing all the arguments for the original call * @return ViewAbstract * * @see http://martinfowler.com/bliki/FluentInterface.html */ public function __call($method, $args) { //If one argument is passed we assume a setter method is being called if (count($args) == 1) { if (method_exists($this, 'set' . ucfirst($method))) { return $this->{'set' . ucfirst($method)}($args[0]); } else { return $this->{$method} = $args[0]; } } return parent::__call($method, $args); }
/** * Initializes the options for the object * * Called from {@link __construct()} as a first step of object instantiation. * * @param ObjectConfig $config Configuration options * @return void */ protected function _initialize(ObjectConfig $config) { $config->append(array('version' => '1.0', 'disposition' => 'inline', 'quote' => '"', 'separator' => ',', 'eol' => "\n"))->append(array('mimetype' => 'text/csv; version=' . $config->version)); parent::_initialize($config); }
/** * Get the view context * * @return ViewContextTemplate */ public function getContext() { $context = new ViewContextTemplate(parent::getContext()); $context->setLayout($this->getLayout()); return $context; }
/** * Set default view template use for rendering on error. * * @param string $tamplateName * @return void */ public static function setDefaultErrorTemplate($tamplateName) { self::$_defaultErrorTemplate = $tamplateName; }
/** * Initializes the config for the object * * Called from {@link __construct()} as a first step of object instantiation. * * @param ObjectConfig $config Configuration options * @return void */ protected function _initialize(ObjectConfig $config) { $config->append(array('behaviors' => array('localizable', 'routable'), 'mimetype' => 'application/vnd.api+json', 'version' => '1.0', 'fields' => array(), 'text_fields' => array('description'))); parent::_initialize($config); }