/** * Index action. * * Call if typed path: * http://phpdays.dev/ * http://phpdays.dev/index * http://phpdays.dev/index/index */ public function indexAction() { $blog = Days_Model::factory('table_blog'); //$categories = Days_Model::factory('table_blog_category'); $this->_view->set('blog_items', $blog->find('last', array('count' => 12))); //$this->_view->set('categories', $categories->find('all')); }
/** * Call method in class Days_Model_Helper_[Name]. * * Part of "php:Days - php5 framework" project (http://phpdays.googlecode.com). * * @copyright Copyright (c) 2009 phpDays foundation (http://phpdays.org) * @license http://www.opensource.org/licenses/mit-license.php The MIT License * @link http://phpdays.googlecode.com/ * @package phpDays * @subpackage phpDays Smarty library * @author Anton Danilchenko <*****@*****.**> * @param Parameters * - name: part of Days_Model_Helper_[Name] * - action: name of method in specified class * - to: name of variable to assign result */ function smarty_function_helper($params, &$smarty) { // check required parameters if (!isset($params['name'])) { throw new Days_Exception('Not passed `name` parameter in smarty plugin `helper`'); } if (!isset($params['to'])) { throw new Days_Exception('Not passed `to` parameter in smarty plugin `helper`'); } // create model $model = Days_Model::factory("helper_{$params['name']}"); // check method if (!isset($params['action'])) { throw new Days_Exception('Not passed `action` parameter in smarty plugin `helper`'); } if (!method_exists($model, $params['action'])) { $class = get_class($model); throw new Days_Exception("Not defined method `{$params['action']}` in class `{$class}`"); } // return result $content = call_user_func(array($model, $params['action'])); $smarty->assign($params['to'], $content); }
/** * Run application. * * @param string $appPath Path to application * @param string $mode Name of configuration file used in work */ private function __construct($appPath, $mode) { // set pathes self::$_libPath = realpath(dirname(__FILE__) . '/..') . '/'; self::$_appPath = realpath($appPath) . '/'; self::$_publicPath = getcwd() . '/'; set_include_path(get_include_path() . PATH_SEPARATOR . self::$_libPath); spl_autoload_register(array(__CLASS__, 'autoload')); Days_Session::init(); // set config main file if (!empty($mode)) { Days_Config::setDefaultConfig($mode); } // set path for config Days_Config::setConfigPath(self::$_appPath . 'config/'); // set debug mode self::$_isDebug = (bool) Days_Config::load()->get('engine/debug', false); // set error level and handler $iErrorLevel = self::isDebug() ? E_ALL | E_STRICT : E_ALL ^ E_NOTICE; error_reporting($iErrorLevel); setlocale(LC_ALL, 'ru_RU.UTF-8', 'RUS', 'RU'); //set timezone if ($timezone = Days_Config::load()->get('engine/timezone', false)) { date_default_timezone_set($timezone); } else { date_default_timezone_set('Europe/Helsinki'); } // not send execution errors to user ob_start(); try { if (Days_Config::load()->get('engine/autorun', 1)) { $autorunClass = "Controller_System_Autorun"; // run predefined class if (class_exists($autorunClass) and is_callable(array($autorunClass, 'run'))) { call_user_func(array($autorunClass, 'run')); } } Days_Event::run('engine.start'); // get url info $controller = Days_Url::getSpec('controller'); $action = Days_Url::getSpec('action'); $ext = Days_Url::getSpec('ext'); Days_Event::run('controller.start'); // set module path Days_Model::setPath(self::appPath() . 'Model/'); // set controller params $controllerClass = "Controller_" . ucfirst($controller); // use index controller for non-exists controllers if (!class_exists($controllerClass) and Days_Config::load()->get('url/virtual')) { $controllerClass = "Controller_Index"; $controller = 'index'; } // set action name $actionMethod = Days_Request::isAjax() ? "{$action}AjaxAction" : "{$action}Action"; // set template path $template = "content/{$controller}/{$action}.{$ext}"; // create controller if (!class_exists($controllerClass)) { throw new Days_Exception("Controller '{$controllerClass}' not found"); } $controllerObj = new $controllerClass($template); if (!$controllerObj instanceof Days_Controller) { throw new Days_Exception("Controller '{$controllerClass}' should be extended from 'Days_Controller'"); } // call init() method for prepare object $controllerObj->init(); Days_Event::run('controller.post.init'); // execute PostAction before call specified action if (Days_Request::isPost()) { $actionPost = "{$action}PostAction"; if (method_exists($controllerObj, $actionPost)) { call_user_func(array($controllerObj, $actionPost)); } } // call specified action if (!method_exists($controllerObj, $actionMethod)) { throw new Days_Exception("Action {$actionMethod} in controller {$controllerClass} not defined"); } $actionResult = call_user_func(array($controllerObj, $actionMethod)); // ajax query if (Days_Request::isAjax()) { if (is_null($actionResult)) { $actionResult = array(); } $content = $actionResult; } else { $controllerObj->setLayout($controller, false); $content = call_user_func(array($controllerObj, 'getContent')); Days_Response::addHeader($ext); } Days_Event::run('controller.end'); // set data to response Days_Response::addContent($content); } catch (Exception $oEx) { // save error message about this query Days_Log::add($oEx->getMessage()); // page not found Days_Response::addHeader(Days_Response::NOT_FOUND); } // save runtime errors for ($iObLevel = ob_get_level(); $iObLevel > 0; $iObLevel--) { $sError = ob_get_contents(); if ('' != $sError) { Days_Log::add("This data printed in scripts: '{$sError}'"); } // close output handler ob_end_clean(); } // save errors Days_Log::save(); Days_Event::run('engine.end'); // send headers to user Days_Event::run('response.send.headers'); Days_Response::sendHeaders(); // send content to user Days_Event::run('response.send.content'); Days_Response::sendContent(); }
public static function setPrefix($prefix) { self::$_prefix = ucfirst($prefix) . '_'; }
/** * Return specified variable (as array key). * * @param string $offset Int or string variable name * @return mixed */ public final function offsetGet($offset) { // magic field name $offset = $this->_table->column($offset); // load virtual value if (!array_key_exists($offset, $this->_table->info()) and !array_key_exists($offset, $this->_values)) { // current row not saved physical if (!isset($this->id)) { return null; } // recive parent table name if (false !== ($pos = strpos($this->_table->name(), "{$offset}_"))) { $tableName = substr($this->_table->name(), 0, $pos) . $offset; } elseif ('child' == $offset or 'parent' == $offset) { $tableName = $this->_table->name(); } else { $tableName = $this->_table->name($offset); } // get referenced rows $referenceTable = Days_Model::factory('table_' . $tableName); $currentTableName = $this->_table->name(); // set column name and value switch ($offset) { case 'child': $currentTableColumnName = $this->_table->column('pid'); $currentTableColumnValue = $this->id; break; case 'parent': $currentTableColumnName = $this->_table->column('pid'); $currentTableColumnValue = $this->pid; break; default: $currentTableColumnName = $this->_table->column('id'); $currentTableColumnValue = $this->id; break; } // join outer table if ($tableName != $currentTableName) { $referenceTable->join($currentTableName); } // find tows by criteria $this->_values[$offset] = $referenceTable->find('all', array('where' => array("{$currentTableName}.{$currentTableColumnName}" => $currentTableColumnValue), 'columns' => array("{$tableName}.*"))); } // return value return isset($this->_values[$offset]) ? $this->_values[$offset] : null; }
/** * Call before all controller actions. */ public function init() { $blog = Days_Model::factory('table_blog_category'); $this->_view->set('categorys', $blog->find('all')); $this->_view->set('title', 'Category'); }
/** * Get posts by category * * Call if typed path: * http://phpdays.dev/blog/category/category_url_name/ */ public function categoryAction() { $blog = Days_Model::factory('table_blog'); $this->_view->set('blog_items', $blog->find('last', array('count' => 12))); }