本文整理汇总了PHP中DataModel::inst方法的典型用法代码示例。如果您正苦于以下问题:PHP DataModel::inst方法的具体用法?PHP DataModel::inst怎么用?PHP DataModel::inst使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DataModel
的用法示例。
在下文中一共展示了DataModel::inst方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: handleItem
public function handleItem($gridField, $request)
{
$controller = $gridField->getForm()->Controller();
$record = $gridField->getList()->byId($request->param("ID"));
$handler = Object::create('GridFieldExpandableForm_ItemRequest', $gridField, $this, $record, $controller, 'DetailForm', $this->formorfields);
return $handler->handleRequest($request, DataModel::inst());
}
示例2: form_appears_and_saves
/**
* @test
*/
public function form_appears_and_saves()
{
Config::inst()->update('Controller', 'extensions', array('QuickFeedbackExtension'));
$controller = new TestController();
$result = $controller->handleRequest(new SS_HTTPRequest('GET', 'form_appears_and_saves'), DataModel::inst());
$body = $result->getBody();
$this->assertContains('Form_QuickFeedbackForm', $body);
$this->assertContains('Form_QuickFeedbackForm_Rating', $body);
$this->assertContains('Form_QuickFeedbackForm_Comment', $body);
preg_match('/action="([^"]+)"/', $body, $action);
if (!count($action)) {
$this->fail('No form action');
}
preg_match('/name="SecurityID" value="([^"]+)"/', $body, $token);
if (!count($action)) {
$this->fail('No token');
}
$parts = explode('/', $action[1]);
$action = end($parts);
$time = time();
$data = ['SecurityID' => $token[1], 'Rating' => '0', 'Comment' => 'comment at ' . $time];
$controller->handleRequest(new SS_HTTPRequest('POST', $action, array(), $data), DataModel::inst());
$existing = Feedback::get()->filter('Comment', 'comment at ' . $time)->first();
if (!$existing) {
$this->fail('Record missing');
}
}
开发者ID:helpfulrobot,项目名称:mandrew-silverstripe-quickfeedback,代码行数:30,代码来源:QuickFeedbackExtensionTest.php
示例3: fireSilverstripeCommand
protected function fireSilverstripeCommand($url)
{
$this->bootSilverstripe($url);
$_SERVER['REQUEST_URI'] = BASE_URL . '/' . $url;
// Direct away - this is the "main" function, that hands control to the appropriate controller
\Director::direct($url, \DataModel::inst());
}
示例4: addfield
public function addfield($gridField, $request)
{
$controller = $gridField->getForm()->Controller();
$record = singleton('MetadataField');
$handler = Object::create('MetaDataFieldAddForm_ItemRequest', $gridField, $this, $record, $controller, $this->name);
$handler->setTemplate($this->template);
return $handler->handleRequest($request, DataModel::inst());
}
示例5: handleManagePresentation
public function handleManagePresentation(SS_HTTPRequest $r)
{
if ($presentation = Presentation::get()->byID($r->param('ID'))) {
$request = PresentationAPI_PresentationRequest::create($presentation, $this);
return $request->handleRequest($r, DataModel::inst());
}
return $this->httpError(404, "Presentation " . $r->param('ID') . " not found");
}
示例6: testRedirectingMapping
/**
* Tests to make sure short codes get translated to full paths.
*
*/
public function testRedirectingMapping()
{
DocumentationPermalinks::add(array('foo' => 'en/framework/subfolder/foo', 'bar' => 'en/cms/bar'));
$this->autoFollowRedirection = false;
$v = new DocumentationViewer();
$response = $v->handleRequest(new SS_HTTPRequest('GET', 'foo'), DataModel::inst());
$this->assertEquals('301', $response->getStatusCode());
$this->assertContains('en/framework/subfolder/foo', $response->getHeader('Location'));
}
示例7: testUnserializeWithExtraData
/**
* @depends testSerializeWithExtraData
* @covers \Heystack\Core\State\Traits\DataObjectSerializableTrait::unserialize
*/
public function testUnserializeWithExtraData($data)
{
$t = $this->getMockForAbstractClass(__NAMESPACE__ . '\\TestDataObjectSerializableTraitWithExtraData');
$t->expects($this->once())->method('setExtraData')->with(['test' => true]);
$t->unserialize($data);
$this->assertAttributeEquals(get_class($t), 'class', $t);
$this->assertAttributeEquals(['test' => true], 'record', $t);
$this->assertAttributeEquals(\DataModel::inst(), 'model', $t);
}
示例8: testProcessDoesProduceExpectedOutput
/**
* @covers \Heystack\Ecommerce\Controller\InputController::__construct
*/
public function testProcessDoesProduceExpectedOutput()
{
$controller = new InputController($inputMock = $this->getMock('Heystack\\Core\\Input\\Handler'), $outptuMock = $this->getMock('Heystack\\Core\\Output\\Handler'));
$request = new \SS_HTTPRequest('GET', '/input/process/test/');
$inputMock->expects($this->once())->method('process')->with('test', $request)->will($this->returnValue(['success' => true]));
$outptuMock->expects($this->once())->method('process')->with('test', $controller, ['success' => true])->will($this->returnValue('yay'));
$response = $controller->handleRequest($request, \DataModel::inst());
$this->assertEquals('yay', $response->getBody());
}
示例9: process
/**
* @return string
*/
public function process()
{
if ($this->siteUrl) {
ob_start();
Director::direct($this->url, \DataModel::inst());
return ob_get_clean();
} else {
return @file_get_contents($this->url);
}
}
示例10: onBeforeHTTPError
/**
* Retrieve the correct error page for the current multisite instance.
* @param integer
* @param SS_HTTPRequest
* @throws SS_HTTPResponse_Exception
*/
public function onBeforeHTTPError($code, $request)
{
$errorPage = ErrorPage::get()->filter(array('ErrorCode' => $code, 'SiteID' => Multisites::inst()->getCurrentSiteId()))->first();
if ($errorPage) {
Requirements::clear();
Requirements::clear_combined_files();
$response = ModelAsController::controller_for($errorPage)->handleRequest($request, DataModel::inst());
throw new SS_HTTPResponse_Exception($response, $code);
}
}
开发者ID:helpfulrobot,项目名称:sheadawson-silverstripe-multisites,代码行数:16,代码来源:MultisitesControllerExtension.php
示例11: testTemplateFunctionsForOtherSteps
public function testTemplateFunctionsForOtherSteps()
{
$summaryRequest = new SS_HTTPRequest('GET', "summary");
$this->checkout = new CheckoutPage_Controller();
$this->checkout->handleRequest($summaryRequest, DataModel::inst());
//change to summary step
$this->assertTrue($this->checkout->StepExists('summary'));
$this->assertFalse($this->checkout->IsPastStep('summary'));
$this->assertTrue($this->checkout->IsCurrentStep('summary'));
$this->assertFalse($this->checkout->IsFutureStep('summary'));
$this->assertFalse($this->checkout->StepExists('nosuchstep'));
}
示例12: process
/**
* @return string
* @throws \RuntimeException
*/
public function process()
{
$result = $this->getHandleMethod()->invoke(null, $this->request, $this->session, \DataModel::inst());
if ($result instanceof SS_HTTPResponse) {
ob_start();
$result->output();
return ob_get_clean();
} elseif (is_string($result)) {
return $result;
} else {
throw new \RuntimeException('Can\'t handle output from request');
}
}
示例13: handleItem
/**
*
* @param type $gridField
* @param type $request
* @return GridFieldDetailForm_ItemRequest
*/
public function handleItem($gridField, $request)
{
$controller = $gridField->getForm()->Controller();
if (is_numeric($request->param('ID'))) {
$record = $gridField->getList()->byId($request->param("ID"));
} else {
$record = Object::create($gridField->getModelClass());
}
$class = $this->getItemRequestClass();
$handler = Object::create($class, $gridField, $this, $record, $controller, $this->name);
$handler->setTemplate($this->template);
return $handler->handleRequest($request, DataModel::inst());
}
示例14: handleItem
public function handleItem($gridField, $request)
{
$controller = $gridField->getForm()->Controller();
// we can't check on is_numeric, since some datasources use strings as identifiers
if ($request->param('ID') && $request->param('ID') != 'new') {
$record = $gridField->getList()->byId($request->param("ID"));
} else {
$record = Object::create($gridField->getModelClass());
}
$class = $this->getItemRequestClass();
$handler = Object::create($class, $gridField, $this, $record, $controller, $this->name);
$handler->setTemplate($this->template);
return $handler->handleRequest($request, DataModel::inst());
}
开发者ID:helpfulrobot,项目名称:axyr-silverstripe-externaldata,代码行数:14,代码来源:ExternalDataGridFieldDetailForm.php
示例15: response_for
/**
* Get a {@link SS_HTTPResponse} to response to a HTTP error code if an {@link ErrorPage} for that code is present.
*
* @param int $statusCode
* @return SS_HTTPResponse
*/
public static function response_for($statusCode)
{
// first attempt to dynamically generate the error page
if ($errorPage = DataObject::get_one('ErrorPage', "\"ErrorCode\" = {$statusCode}")) {
return ModelAsController::controller_for($errorPage)->handleRequest(new SS_HTTPRequest('GET', ''), DataModel::inst());
}
// then fall back on a cached version
$cachedPath = self::get_filepath_for_errorcode($statusCode, class_exists('Translatable') ? Translatable::get_current_locale() : null);
if (file_exists($cachedPath)) {
$response = new SS_HTTPResponse();
$response->setStatusCode($statusCode);
$response->setBody(file_get_contents($cachedPath));
return $response;
}
}