<?php
namespace sfase;
/**
* Controller is the base class for classes containing controller logic.
* @author Harry Sun <sunguangjun@126.com>
*/
class Controller
{
}
立即学习“PHP免费学习笔记(深入)”;
<?php
namespace sfweb;
/**
* Controller is the base class for classes containing controller logic.
* @author Harry Sun <sunguangjun@126.com>
*/
class Controller extends sfaseController
{
/**
* Renders a view
* @param string $view the view name.
* @param array $params the parameters (name-value pairs) that should be made available in the view.
*/
public function render($view, $params = [])
{
extract($params);
return require '../views/' . $view . '.php';
}
}
立即学习“PHP免费学习笔记(深入)”;
<?php
namespace appcontrollers;
use sfwebController;
class SiteController extends Controller
{
public function actionTest()
{
echo 'success!';
}
public function actionView()
{
$this->render('site/view', ['body' => 'Test body information']);
}
}
立即学习“PHP免费学习笔记(深入)”;
<?php
namespace sfase;
/**
* Controller is the base class for classes containing controller logic.
* @author Harry Sun <sunguangjun@126.com>
*/
class Controller
{
/**
* @var string the ID of this controller.
*/
public $id;
/**
* @var Action the action that is currently being executed.
*/
public $action;
}
立即学习“PHP免费学习笔记(深入)”;
<?php
namespace sfweb;
/**
* Application is the base class for all application classes.
* @author Harry Sun <sunguangjun@126.com>
*/
class Application extends sfaseApplication
{
/**
* Handles the specified request.
* @return Response the resulting response
*/
public function handleRequest()
{
$router = $_GET['r'];
list($controllerName, $actionName) = explode('/', $router);
$ucController = ucfirst($controllerName);
$controllerNameAll = $this->controllerNamespace . '\' . $ucController . 'Controller';
$controller = new $controllerNameAll();
$controller->id = $controllerName;
$controller->action = $actionName;
return call_user_func([$controller, 'action'. ucfirst($actionName)]);
}
}
立即学习“PHP免费学习笔记(深入)”;
<html>
<head>
<title>title</title>
<head>
<body>
<?php echo $this->id;?><br/>
<?php echo $this->action;?><br/>
<?php echo $body;?>
</body>
</html>
立即学习“PHP免费学习笔记(深入)”;
/**
* Convert a array to json string
* @param string $data
*/
public function toJson($data)
{
if (is_string($data)) {
return $data;
}
return json_encode($data);
}
立即学习“PHP免费学习笔记(深入)”;
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号