当前位置: 首页>>代码示例>>PHP>>正文


PHP CakeResponse::type方法代码示例

本文整理汇总了PHP中CakeResponse::type方法的典型用法代码示例。如果您正苦于以下问题:PHP CakeResponse::type方法的具体用法?PHP CakeResponse::type怎么用?PHP CakeResponse::type使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CakeResponse的用法示例。


在下文中一共展示了CakeResponse::type方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: _deliverMedia

 protected function _deliverMedia(CakeResponse $response, $mediaFile, $mediaInfo)
 {
     $response->sharable(true, 2592000);
     //$response->mustRevalidate(true);
     $response->expires('+30 days');
     $modTime = filemtime($mediaFile);
     $response->modified($modTime);
     $response->etag(md5($mediaFile . $modTime));
     //$response->header("Pragma", "cache");
     $response->type($mediaInfo['ext']);
     $response->file($mediaFile);
     $response->send();
 }
开发者ID:nilBora,项目名称:konstruktor,代码行数:13,代码来源:MediaDispatcher.php

示例2: _deliver

 protected function _deliver(CakeResponse $response, Asset $asset)
 {
     ob_start();
     $compressionEnabled = Configure::read('Asset.compress') && $response->compress();
     if ($response->type($asset->extension()) == $asset->extension()) {
         $contentType = 'application/octet-stream';
         $agent = env('HTTP_USER_AGENT');
         if (preg_match('%Opera(/| )([0-9].[0-9]{1,2})%', $agent) || preg_match('/MSIE ([0-9].[0-9]{1,2})/', $agent)) {
             $contentType = 'application/octetstream';
         }
         $response->type($contentType);
     }
     if (!$compressionEnabled) {
         $response->header('Content-Length', $asset->size());
     }
     $response->cache(filemtime($asset->file));
     $response->send();
     ob_clean();
     echo $asset->content();
     if ($compressionEnabled) {
         ob_end_flush();
     }
 }
开发者ID:rodrigorm,项目名称:asset-plugin,代码行数:23,代码来源:AssetsDispatcher.php

示例3: testRenderWithView

 /**
  * testRenderWithView method
  *
  * @return void
  */
 public function testRenderWithView()
 {
     App::build(array('View' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'View' . DS)));
     $Request = new CakeRequest();
     $Response = new CakeResponse();
     $Controller = new Controller($Request, $Response);
     $Controller->name = $Controller->viewPath = 'Posts';
     $data = array('User' => array('username' => 'fake'), 'Item' => array(array('name' => 'item1'), array('name' => 'item2')));
     $Controller->set('user', $data);
     $View = new JsonView($Controller);
     $output = $View->render('index');
     $expected = json_encode(array('user' => 'fake', 'list' => array('item1', 'item2')));
     $this->assertIdentical($expected, $output);
     $this->assertIdentical('application/json', $Response->type());
 }
开发者ID:rufl,项目名称:ATP,代码行数:20,代码来源:JsonViewTest.php

示例4: testRenderWithView

 /**
  * testRenderWithView method
  *
  * @return void
  */
 public function testRenderWithView()
 {
     App::build(array('View' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'View' . DS)));
     $Request = new CakeRequest();
     $Response = new CakeResponse();
     $Controller = new Controller($Request, $Response);
     $Controller->name = $Controller->viewPath = 'Posts';
     $data = array(array('User' => array('username' => 'user1')), array('User' => array('username' => 'user2')));
     $Controller->set('users', $data);
     $View = new XmlView($Controller);
     $output = $View->render('index');
     $expected = '<?xml version="1.0" encoding="UTF-8"?><users><user>user1</user><user>user2</user></users>';
     $this->assertIdentical($expected, str_replace(array("\r", "\n"), '', $output));
     $this->assertIdentical('application/xml', $Response->type());
     $this->assertInstanceOf('HelperCollection', $View->Helpers);
 }
开发者ID:MrGrigorev,项目名称:reserva-de-salas,代码行数:21,代码来源:XmlViewTest.php

示例5: _deliverAsset

 /**
  * Sends an asset file to the client
  *
  * @param string $assetFile Path to the asset file in the file system
  * @param string $ext The extension of the file to determine its mime type
  * @return void
  */
 protected function _deliverAsset($assetFile, $ext)
 {
     ob_start();
     $compressionEnabled = Configure::read('Asset.compress') && $this->response->compress();
     if ($this->response->type($ext) == $ext) {
         $contentType = 'application/octet-stream';
         $agent = env('HTTP_USER_AGENT');
         if (preg_match('%Opera(/| )([0-9].[0-9]{1,2})%', $agent) || preg_match('/MSIE ([0-9].[0-9]{1,2})/', $agent)) {
             $contentType = 'application/octetstream';
         }
         $this->response->type($contentType);
     }
     $this->response->cache(filemtime($assetFile));
     $this->response->send();
     ob_clean();
     if ($ext === 'css' || $ext === 'js') {
         include $assetFile;
     } else {
         readfile($assetFile);
     }
     if ($compressionEnabled) {
         ob_end_flush();
     }
 }
开发者ID:robotarmy,项目名称:Phog,代码行数:31,代码来源:dispatcher.php

示例6: testRenderWithView

 /**
  * testRenderWithView method
  *
  * @return void
  */
 public function testRenderWithView()
 {
     App::build(array('View' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'View' . DS)));
     $Request = new CakeRequest();
     $Response = new CakeResponse();
     $Controller = new Controller($Request, $Response);
     $Controller->name = $Controller->viewPath = 'Posts';
     $data = array(array('User' => array('username' => 'user1')), array('User' => array('username' => 'user2')));
     $Controller->set('users', $data);
     $View = new XmlView($Controller);
     $output = $View->render('index');
     $expected = array('users' => array('user' => array('user1', 'user2')));
     $expected = Xml::build($expected)->asXML();
     $this->assertSame($expected, $output);
     $this->assertSame('application/xml', $Response->type());
     $this->assertInstanceOf('HelperCollection', $View->Helpers);
 }
开发者ID:ophilli,项目名称:Inventory,代码行数:22,代码来源:XmlViewTest.php

示例7: testType

 /**
  * Tests the type method
  *
  */
 public function testType()
 {
     $response = new CakeResponse();
     $this->assertEquals('text/html', $response->type());
     $response->type('pdf');
     $this->assertEquals('application/pdf', $response->type());
     $this->assertEquals('application/crazy-mime', $response->type('application/crazy-mime'));
     $this->assertEquals('application/json', $response->type('json'));
     $this->assertEquals('text/vnd.wap.wml', $response->type('wap'));
     $this->assertEquals('application/vnd.wap.xhtml+xml', $response->type('xhtml-mobile'));
     $this->assertEquals('text/csv', $response->type('csv'));
     $response->type(array('keynote' => 'application/keynote', 'bat' => 'application/bat'));
     $this->assertEquals('application/keynote', $response->type('keynote'));
     $this->assertEquals('application/bat', $response->type('bat'));
     $this->assertFalse($response->type('wackytype'));
 }
开发者ID:pushpendraraj,项目名称:tigzie,代码行数:20,代码来源:CakeResponseTest.php

示例8: responseType

 /**
  * Returns the current response type (Content-type header), or null if not alias exists
  *
  * @return mixed A string content type alias, or raw content type if no alias map exists,
  *	otherwise null
  */
 public function responseType()
 {
     return $this->mapType($this->response->type());
 }
开发者ID:rednazj,项目名称:Inventory,代码行数:10,代码来源:RequestHandlerComponent.php

示例9: testWithoutSubdir

 /**
  * AjaxViewTest::testWithoutSubdir()
  *
  * @return void
  */
 public function testWithoutSubdir()
 {
     $Request = new CakeRequest();
     $Response = new CakeResponse();
     $Controller = new Controller($Request, $Response);
     $View = new AjaxView($Controller);
     $View->viewPath = 'Items';
     $View->subDir = false;
     $result = $View->render('index');
     $this->assertSame('application/json', $Response->type());
     $expected = array('error' => null, 'content' => 'My Index Test ctp');
     $expected = json_encode($expected);
     $this->assertTextEquals($expected, $result);
 }
开发者ID:Jony01,项目名称:LLD,代码行数:19,代码来源:AjaxViewTest.php

示例10: testRenderWithView

 /**
  * testRenderWithView method
  *
  * @return void
  */
 public function testRenderWithView()
 {
     App::build(array('View' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'View' . DS)));
     $Request = new CakeRequest(null, false);
     $Request->params['named'] = array('page' => 2);
     $Response = new CakeResponse();
     $Controller = new Controller($Request, $Response);
     $Controller->name = $Controller->viewPath = 'Posts';
     $data = array('User' => array('username' => 'fake'), 'Item' => array(array('name' => 'item1'), array('name' => 'item2')));
     $Controller->set('user', $data);
     $View = new JsonView($Controller);
     $View->helpers = array('Paginator');
     $output = $View->render('index');
     $expected = array('user' => 'fake', 'list' => array('item1', 'item2'), 'paging' => array('page' => 2));
     $this->assertSame(json_encode($expected), $output);
     $this->assertSame('application/json', $Response->type());
     $View->request->query = array('jsonCallback' => 'jfunc');
     $Controller->set('_jsonp', 'jsonCallback');
     $View = new JsonView($Controller);
     $View->helpers = array('Paginator');
     $output = $View->render('index');
     $expected['paging']['?']['jsonCallback'] = 'jfunc';
     $expected = 'jfunc(' . json_encode($expected) . ')';
     $this->assertSame($expected, $output);
     $this->assertSame('application/javascript', $Response->type());
 }
开发者ID:beyondkeysystem,项目名称:testone,代码行数:31,代码来源:JsonViewTest.php

示例11: render

 /**
  * Display or download the given file
  *
  * @param string $view Not used
  * @param string $layout Not used
  * @return mixed
  * @throws NotFoundException
  */
 public function render($view = null, $layout = null)
 {
     $name = $download = $extension = $id = $modified = $path = $cache = $mimeType = $compress = null;
     extract($this->viewVars, EXTR_OVERWRITE);
     if (is_dir($path)) {
         $path = $path . $id;
     } else {
         $path = APP . $path . $id;
     }
     if (!is_file($path)) {
         if (Configure::read('debug')) {
             throw new NotFoundException(sprintf('The requested file %s was not found', $path));
         }
         throw new NotFoundException('The requested file was not found');
     }
     if (is_array($mimeType)) {
         $this->response->type($mimeType);
     }
     if (isset($extension) && $this->_isActive()) {
         $extension = strtolower($extension);
         $chunkSize = 8192;
         $buffer = '';
         $fileSize = @filesize($path);
         $handle = fopen($path, 'rb');
         if ($handle === false) {
             return false;
         }
         if (!empty($modified) && !is_numeric($modified)) {
             $modified = strtotime($modified, time());
         } else {
             $modified = time();
         }
         if ($this->response->type($extension) === false) {
             $download = true;
         }
         if ($cache) {
             $this->response->cache($modified, $cache);
         } else {
             $this->response->header(array('Date' => gmdate('D, d M Y H:i:s', time()) . ' GMT', 'Expires' => '0', 'Cache-Control' => 'private, must-revalidate, post-check=0, pre-check=0', 'Pragma' => 'no-cache'));
         }
         if ($download) {
             $agent = env('HTTP_USER_AGENT');
             if (preg_match('%Opera(/| )([0-9].[0-9]{1,2})%', $agent)) {
                 $contentType = 'application/octetstream';
             } else {
                 if (preg_match('/MSIE ([0-9].[0-9]{1,2})/', $agent)) {
                     $contentType = 'application/force-download';
                 }
             }
             if (!empty($contentType)) {
                 $this->response->type($contentType);
             }
             if (is_null($name)) {
                 $name = $id;
             }
             $this->response->download($name);
             $this->response->header(array('Accept-Ranges' => 'bytes'));
             $httpRange = env('HTTP_RANGE');
             if (isset($httpRange)) {
                 list($toss, $range) = explode('=', $httpRange);
                 $size = $fileSize - 1;
                 $length = $fileSize - $range;
                 $this->response->header(array('Content-Length' => $length, 'Content-Range' => 'bytes ' . $range . $size . '/' . $fileSize));
                 $this->response->statusCode(206);
                 fseek($handle, $range);
             } else {
                 $this->response->header('Content-Length', $fileSize);
             }
         } else {
             $this->response->header(array('Content-Length' => $fileSize));
         }
         $this->_clearBuffer();
         if ($compress) {
             $this->_compressionEnabled = $this->response->compress();
         }
         $this->response->send();
         return $this->_sendFile($handle);
     }
     return false;
 }
开发者ID:Chromedian,项目名称:inventory,代码行数:88,代码来源:MediaView.php

示例12: testSerializeWithArrayLinks

    /**
     * RssViewTest::testSerializeWithArrayLinks()
     *
     * `'atom:link' => array('@href' => array(...)` becomes
     * '@rel' => 'self', '@type' => 'application/rss+xml' automatically set for atom:link
     *
     * @return void
     */
    public function testSerializeWithArrayLinks()
    {
        $Request = new CakeRequest();
        $Response = new CakeResponse();
        $Controller = new Controller($Request, $Response);
        $data = array('channel' => array('title' => 'Channel title', 'link' => 'http://channel.example.org', 'atom:link' => array('@href' => array('controller' => 'foo', 'action' => 'bar')), 'description' => 'Channel description'), 'items' => array(array('title' => 'Title One', 'link' => array('controller' => 'foo', 'action' => 'bar'), 'description' => 'Content one'), array('title' => 'Title Two', 'link' => array('controller' => 'foo', 'action' => 'bar'), 'description' => 'Content two')));
        $Controller->set(array('channel' => $data, '_serialize' => 'channel'));
        $View = new RssView($Controller);
        $result = $View->render(false);
        $expected = <<<RSS
<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0">
  <channel>
    <title>Channel title</title>
    <link>http://channel.example.org</link>
    <atom:link href="{$this->baseUrl}/foo/bar" rel="self" type="application/rss+xml"/>
    <description>Channel description</description>
    <item>
      <title>Title One</title>
      <link>{$this->baseUrl}/foo/bar</link>
      <description>Content one</description>
    </item>
    <item>
      <title>Title Two</title>
      <link>{$this->baseUrl}/foo/bar</link>
      <description>Content two</description>
    </item>
  </channel>
</rss>

RSS;
        //debug($result);
        $this->assertSame('application/rss+xml', $Response->type());
        $this->assertTextEquals($expected, $result);
    }
开发者ID:Jony01,项目名称:LLD,代码行数:43,代码来源:RssViewTest.php

示例13: testRenderWithSpecialCharacters

    /**
     * CsvViewTest::testRenderWithSpecialCharacters()
     *
     * @return void
     */
    public function testRenderWithSpecialCharacters()
    {
        App::build(array('View' => realpath(dirname(__FILE__) . DS . '..' . DS . '..' . DS . 'test_app' . DS . 'View' . DS) . DS));
        $Request = new CakeRequest();
        $Response = new CakeResponse();
        $Controller = new Controller($Request, $Response);
        $Controller->name = $Controller->viewPath = 'Posts';
        $data = array(array('User' => array('username' => 'José'), 'Item' => array('type' => 'äöü')), array('User' => array('username' => 'Including,Comma'), 'Item' => array('name' => 'Containing"char', 'type' => 'Containing\'char')), array('User' => array('username' => 'Some Space'), 'Item' => array('name' => "A\nNewline", 'type' => "A\tTab")));
        $_extract = array('User.username', 'Item.name', 'Item.type');
        $Controller->set(array('user' => $data, '_extract' => $_extract));
        $Controller->set(array('_serialize' => 'user'));
        $View = new CsvView($Controller);
        $output = $View->render(false);
        $expected = <<<CSV
José,NULL,äöü
"Including,Comma","Containing""char",Containing'char
"Some Space","A
Newline","A\tTab"

CSV;
        $this->assertTextEquals($expected, $output);
        $this->assertSame('text/csv', $Response->type());
    }
开发者ID:rrd108,项目名称:cakephp-csvview,代码行数:28,代码来源:CsvViewTest.php

示例14: download

 /**
  * ダウンロード
  *
  * @param string $filename ダウンロード時のファイル名
  * @return CakeResponse
  */
 public function download($filename)
 {
     $response = new CakeResponse();
     $response->type('text/csv');
     $response->file($this->path, ['name' => $filename, 'download' => 'true']);
     return $response;
 }
开发者ID:s-nakajima,项目名称:files,代码行数:13,代码来源:CsvFileWriter.php

示例15: download

 /**
  * Download
  *
  * @param string $filename download時のファイル名
  * @return CakeResponse ダウンロードレスポンス
  */
 public function download($filename)
 {
     // closeされてなかったらcloseする
     if ($this->_open) {
         $this->close();
     }
     $response = new CakeResponse();
     $response->type('application/zip');
     $response->file($this->path, ['name' => $filename, 'download' => 'true']);
     return $response;
 }
开发者ID:s-nakajima,项目名称:files,代码行数:17,代码来源:ZipDownloader.php


注:本文中的CakeResponse::type方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。