本文整理汇总了PHP中controller::action方法的典型用法代码示例。如果您正苦于以下问题:PHP controller::action方法的具体用法?PHP controller::action怎么用?PHP controller::action使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类controller
的用法示例。
在下文中一共展示了controller::action方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: run
/**
* The method finds in the controller directory and runs action, selected
* in accordance with the incoming parameter.
* @param type $action
* @return string
* @throws Exception
* @version 14.11.2014
*/
public static function run($action = "index")
{
if (empty($action)) {
$action = "index";
}
// Determine, whether the controller is selected.
if (empty(self::$controller)) {
throw new Exception(_("Controller parameter is not set."));
}
// For security purposes, we will add additional validation
// on user input.
if (!preg_match("/[-_0-9a-z]{2,15}/u", $action)) {
throw new Exception(_("Controller Action parameter is not valid."));
}
self::$action = $action;
// Define path to the actions of selected controller.
$SubControllerPath = MODULE_PATH . "controller-" . self::$controller . "/";
// If Action file is not found - return false. Else - include it.
if (!is_file($SubControllerPath . $action . ".php")) {
throw new Exception(_("Controller Action is not found."));
}
require_once $SubControllerPath . $action . ".php";
// Define Contoller Action function name and run it.
$ActFunction = "controller_" . self::$controller . "_" . $action;
if (!function_exists($ActFunction)) {
throw new Exception(_("Controller Action is not found."));
}
return $ActFunction();
}
示例2: model
<?php
include_once 'controller/controller.php';
$model = new model();
$view = new view();
$controller = new controller($model, $view);
echo $controller->action();