本文整理汇总了PHP中Dispatcher::get_controller方法的典型用法代码示例。如果您正苦于以下问题:PHP Dispatcher::get_controller方法的具体用法?PHP Dispatcher::get_controller怎么用?PHP Dispatcher::get_controller使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Dispatcher
的用法示例。
在下文中一共展示了Dispatcher::get_controller方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: models
/**
* Carga modelos
*
* @param string $model
* @throw KumbiaException
**/
public static function models($model = null)
{
/**
* Si se utiliza base de datos
**/
if (!class_exists('Db', false)) {
require CORE_PATH . 'libs/db/db.php';
}
$controller = Dispatcher::get_controller();
if (!$model) {
self::_all_models($controller);
return;
} elseif (is_array($model)) {
$args = $model;
} else {
$args = func_get_args();
}
foreach ($args as $model) {
$file = APP_PATH . "models/{$model}.php";
if (is_file($file)) {
include_once $file;
if ($controller) {
$Model = Util::camelcase(basename($model));
$controller->{$Model} = new $Model();
self::$_injected_models[] = $Model;
}
} elseif (is_dir(APP_PATH . "models/{$model}")) {
self::_all_models($controller, $dir);
} else {
throw new KumbiaException("Modelo {$model} no encontrado");
}
}
}
示例2: handle_exception
/**
* Maneja las excepciones no capturadas
*
* @param Exception $e
**/
public static function handle_exception($e)
{
if (isset($e->_view) && ($e->_view == 'no_controller' || $e->_view == 'no_action')) {
header('HTTP/1.1 404 Not Found');
} else {
header('HTTP/1.1 500 Internal Server Error');
}
extract(Router::get(), EXTR_OVERWRITE);
$Controller = Util::camelcase($controller);
ob_start();
if (!PRODUCTION) {
$Template = 'views/templates/exception.phtml';
$boot = Config::read('boot');
if (isset($e->_view)) {
include CORE_PATH . "views/errors/{$e->_view}.phtml";
} else {
include CORE_PATH . "views/errors/exception.phtml";
}
} else {
include APP_PATH . 'views/errors/404.phtml';
$Template = 'views/templates/error.phtml';
}
$content = ob_get_clean();
// termina los buffers abiertos
while (ob_get_level()) {
ob_end_clean();
}
// verifica si esta cargado el dispatcher
if (class_exists('Dispatcher')) {
$controller = Dispatcher::get_controller();
if ($controller && $controller->response == 'view') {
echo $content;
exit;
}
}
include CORE_PATH . $Template;
}
示例3: get_value_from_action
/**
* Obtiene el valor de un componente tomado
* del mismo valor del nombre del campo en el modelo
* del mismo nombre del controlador o el indice en
* $_REQUEST
*
* @param string $name
* @return mixed
*/
function get_value_from_action($name)
{
$p = explode('.', $name);
if (count($p) > 1) {
$value = get_value_from_action($p[0]);
if (is_object($value) && isset($value->{$p}[1])) {
return $value->{$p}[1];
} elseif (is_array($value) && isset($value[$p[1]])) {
return $value[$p[1]];
} else {
return '';
}
} else {
$controller = Dispatcher::get_controller();
if (isset($controller->{$name})) {
return $controller->{$name};
} else {
return "";
}
}
}
示例4: getFieldValue
/**
* Obtiene el valor del campo por autocarga de valores
*
* @param string $field nombre de campo
* @return mixed retorna NULL si no existe valor por autocarga
*/
public static function getFieldValue($field)
{
// Obtiene considerando el patron de formato form.field
$formField = explode('.', $field, 2);
// Obtiene el controller
$controller = Dispatcher::get_controller();
// Valor por defecto
$value = NULL;
// Si tiene el formato form.field
if (isset($formField[1])) {
// Si existe un valor cargado
if (isset($controller->{$formField[0]})) {
$form = $controller->{$formField[0]};
if (is_object($form) && isset($form->{$formField[1]})) {
$value = $form->{$formField[1]};
} elseif (is_array($form) && isset($form[$formField[1]])) {
$value = $form[$formField[1]];
}
} elseif (isset($_POST[$formField[0]][$formField[1]])) {
$value = $_POST[$formField[0]][$formField[1]];
}
} else {
// Formato de campo comun
// Si existe un valor cargado
if (isset($controller->{$field})) {
$value = $controller->{$field};
} elseif (isset($_POST[$field])) {
$value = $_POST[$field];
}
}
// Retorna el valor de campo
return $value;
}
示例5: update_from_request
/**
* Updates a Row using values from $_REQUEST
*
* @param string $form form name for request, equivalent to $_REQUEST[$form]
* @return boolean success
*/
public function update_from_request($form = null)
{
if (!$form) {
$form = $this->source;
}
$result = $this->update($_REQUEST[$form]);
if (!$result) {
Dispatcher::get_controller()->{$form} = $_REQUEST[$form];
}
return $result;
}