本文整理汇总了PHP中Controller::getResponse方法的典型用法代码示例。如果您正苦于以下问题:PHP Controller::getResponse方法的具体用法?PHP Controller::getResponse怎么用?PHP Controller::getResponse使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Controller
的用法示例。
在下文中一共展示了Controller::getResponse方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __get
/**
* Overriding parent
*
* @param string $name
* @return mixed
*/
public function __get($name)
{
// View
if ($name == 'view') {
return $this->_controllerInstance->getView();
}
// Request
if ($name == 'request') {
return $this->_controllerInstance->getRequest();
}
// Response
if ($name == 'response') {
return $this->_controllerInstance->getResponse();
}
// POST
if ($name == 'post') {
return $this->_controllerInstance->getRequest()->getPost();
}
// GET
if ($name == 'query') {
return $this->_controllerInstance->getRequest()->getQuery();
}
// URL parameters
if ($name == 'params') {
return $this->_controllerInstance->getRequest()->getParams();
}
// application env
if ($name == 'appEnv') {
return $this->_controllerInstance->getAppEnv();
}
parent::__get($name);
}
示例2: show_access_message
/**
*
* Adapted and simplified from {@link Security::permissionFailure()}.
*
* @param Controller $controller
* @param string $message
* @return SS_HTTPResponse $response
*/
public static function show_access_message($controller, $message = '')
{
$response = $controller->getResponse();
$response->setBody($message);
$response->setStatusDescription($message);
$response->setStatusCode(403);
return $response;
}
示例3: process
/**
* Executes the main functionality of the output processor
*
* @param \Controller $controller The relevant SilverStripe controller
* @param mixed $result The result from the input processor
* @return \SS_HTTPResponse
*/
public function process(\Controller $controller, $result = null)
{
$response = $controller->getResponse();
$response->setStatusCode(200);
$response->addHeader('Content-Type', 'application/json');
$response->setBody(json_encode(['success' => (bool) $result]));
return $response;
}
开发者ID:heyday,项目名称:heystack-ecommerce-locationdetectionmanager,代码行数:15,代码来源:SetCountryOutputProcessor.php
示例4: process
/**
* Executes the main functionality of the output processor
*
* @param \Controller $controller The relevant SilverStripe controller
* @param mixed $result The result from the input processor
* @return mixed|null
*/
public function process(\Controller $controller, $result = null)
{
if ($controller->getRequest()->isAjax()) {
$response = $controller->getResponse();
$response->setStatusCode(200);
$response->addHeader('Content-Type', 'application/json');
$response->setBody(json_encode($result));
return $response;
} else {
$controller->redirectBack();
}
return null;
}
示例5: getResponse
public function getResponse()
{
// AJAX response with flash messages always returns JSON response.
// But do not create a new JsonResponse if response already is one...
if ($this->is_ajax) {
header('X-path: ' . (isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '/'));
if (count($this->flash) > 0 && !$this->response instanceof Response\JsonResponse) {
$old_response = parent::getResponse();
$this->response = new Response\JsonResponse();
$this->set('content', $old_response->renderToString());
}
}
$this->set('flash', $this->flash);
return parent::getResponse();
}
示例6: _output
/**
* Outputs the content of a scaffold method passing it through the Controller::afterFilter()
*
* @return void
*/
protected function _output()
{
$this->controller->afterFilter();
$this->controller->getResponse()->send();
}
示例7: getResponse
function getResponse()
{
return parent::getResponse();
}
示例8: permissionFailure
/**
* Register that we've had a permission failure trying to view the given page
*
* This will redirect to a login page.
* If you don't provide a messageSet, a default will be used.
*
* @param Controller $controller The controller that you were on to cause the permission
* failure.
* @param string|array $messageSet The message to show to the user. This
* can be a string, or a map of different
* messages for different contexts.
* If you pass an array, you can use the
* following keys:
* - default: The default message
* - logInAgain: The message to show
* if the user has just
* logged out and the
* - alreadyLoggedIn: The message to
* show if the user
* is already logged
* in and lacks the
* permission to
* access the item.
*/
static function permissionFailure($controller = null, $messageSet = null) {
if(Director::is_ajax()) {
$response = ($controller) ? $controller->getResponse() : new HTTPResponse();
$response->setStatusCode(403);
$response->setBody('NOTLOGGEDIN:');
return $response;
} else {
// Prepare the messageSet provided
if(!$messageSet) {
if(self::$default_message_set) {
$messageSet = self::$default_message_set;
} else {
$messageSet = array(
'default' => _t(
'Security.NOTEPAGESECURED',
"That page is secured. Enter your credentials below and we will send you right along."
),
'alreadyLoggedIn' => _t(
'Security.ALREADYLOGGEDIN',
"You don't have access to this page. If you have another account that can access that page, you can log in below."
),
'logInAgain' => _t(
'Security.LOGGEDOUT',
"You have been logged out. If you would like to log in again, enter your credentials below."
)
);
}
}
if(!is_array($messageSet)) {
$messageSet = array('default' => $messageSet);
}
// Work out the right message to show
if(Member::currentUserID()) {
$message = isset($messageSet['alreadyLoggedIn']) ? $messageSet['alreadyLoggedIn'] : $messageSet['default'];
if($member = Member::currentUser()) {
$member->logOut();
}
} else if(substr(Director::history(),0,15) == 'Security/logout') {
$message = $messageSet['logInAgain'] ? $messageSet['logInAgain'] : $messageSet['default'];
} else {
$message = $messageSet['default'];
}
Session::set("Security.Message.message", $message);
Session::set("Security.Message.type", 'warning');
Session::set("BackURL", $_SERVER['REQUEST_URI']);
// TODO AccessLogEntry needs an extension to handle permission denied errors
// Audit logging hook
if($controller) $controller->extend('permissionDenied', $member);
Director::redirect("Security/login");
}
return;
}
示例9: testGetResponse
public function testGetResponse()
{
$this->container->expects($this->once())->method('getInstanceOf')->with($this->equalTo('response_service'))->will($this->returnValue($this->getMock('IResponse')));
$this->assertThat($this->object->getResponse(), $this->isInstanceOf('IResponse'));
}
示例10: _invoke
/**
* Initializes the components and models a controller will be using.
* Triggers the controller action, and invokes the rendering if Controller::$autoRender is true and echo's the output.
* Otherwise the return value of the controller action are returned.
*
* @param Controller $controller Controller to invoke
* @param CakeRequest $request The request object to invoke the controller for.
* @return string Output as sent by controller
* @throws MissingActionException when the action being called is missing.
*/
protected function _invoke(Controller $controller, CakeRequest $request)
{
$controller->constructClasses();
$controller->startupProcess();
$methods = array_flip($controller->methods);
if (!isset($methods[$request->params['action']])) {
if ($controller->scaffold !== false) {
App::import('Controller', 'Scaffold', false);
return new Scaffold($controller, $request);
}
throw new MissingActionException(array('controller' => Inflector::camelize($request->params['controller']) . "Controller", 'action' => $request->params['action']));
}
$result = call_user_func_array(array(&$controller, $request->params['action']), $request->params['pass']);
$response = $controller->getResponse();
if ($controller->autoRender) {
$controller->render();
} elseif ($response->body() === null) {
$response->body($result);
}
$controller->shutdownProcess();
if (isset($request->params['return'])) {
return $response->body();
}
$response->send();
}
示例11: getResponse
/**
* test getResponse() method
*
* @test
*/
public function getResponse()
{
$this->generateComponent();
$this->Api->setResponse(['very' => ['deep' => ['array' => ['test']]]]);
$this->assertSame('test', $this->Api->getResponse('very.deep.array.0'));
}