Controller 소개
고도몰의 Controller 를 소개하는 내용입니다.
Last updated
<?php
namespace Bundle\Controller\Front\Test;
class MyController extends \Controller\Front\Controller {
public function index() {
something();
}
}<?php
namespace Bundle\Controller\Mobile\Test;
class MyController extends \Controller\Mobile\Controller {
public function index() {
something();
}
}<?php
namespace Bundle\Controller\Admin\Test;
class MyController extends \Controller\Admin\Controller {
public function index() {
something();
}
}<?php
namespace Bundle\Widget\Front\Test;
class MyWidget extends \Widget\Front\Widget {
public function index() {
something();
}
}<?php
namespace Bundle\Controller\Api\Test;
class MyController extends \Controller\Api\Controller {
public function index() {
something();
}
}<?php
namespace Bundle\Controller\Front\Test;
class MyController extends \Controller\Front\Test\Controller {
protected function func() {
return '456';
}
}[ 'test' => '456' ]<?php
namespace Bundle\Controller\Api\Test;
class MyController extends \Controller\Api\Test\Controller {
protected function func() {
// some code ...
}
}<?php
namespace Bundle\Controller\Front\Goods;
class GoodsListController extends \Controller\Front\Controller {
public function index() {
$this->setData('data', 'original');
}
}<?php
$data['data'] = 'not original';
$data['data2'] = 'new data';<?php
namespace Bundle\Controller\[Front|Admin|Mobile]\Test;
class MyController extends \Controller\[Front|Admin|Mobile]\Controller {
public function index() {
// somecode or data handling
}
}<?php
namespace Bundle\Controller\[Front|Admin|Mobile]\Test;
class MyController extends \Controller\[Front|Admin|Mobile]\Controller {
public function index() {
// case 1
$this->setData('wrapper', [
'test1' => 1,
'test2' => 2,
'test3' => 3,
]);
$this->json();
// case 2
$data = [
'wrapper' => [
'test1' => 1,
'test2' => 2,
'test3' => 3,
]
]);
$this->json($data);
}
}<?php
namespace Bundle\Controller\[Front|Admin|Mobile]\Test;
class MyController extends \Controller\[Front|Admin|Mobile]\Controller {
public function index() {
// 파일경로와 파일명을 인자로 넘기면 즉시 다운로드가 실행됩니다
$this->download(UserFilePath::frontSkin('mera_ws','img','btn_19out.gif'), 'sample_test.gif');
}
}<?php
namespace Bundle\Controller\[Front|Admin|Mobile]\Test;
class MyController extends \Controller\[Front|Admin|Mobile]\Controller {
/**
* index() 함수내 echo를 이용해 화면에 출력하면
* 출력 버퍼를 이용해 파일로 저장합니다.
*/
public function index() {
// case 1
echo '인덱스내에 스트링을 출력하면 해당 내용이 결과로 저장되며, 파일 확장자에 따라서 자동으로 Mime-Type이 설정됩니다.';
$this->streamedDownload('sample_test.txt');
// case 2
echo '<table><tr><td>엑셀</td></tr></table>';
$this->streamedDownload('sample_test.xls');
}
}<?php
namespace Bundle\Controller\[Front|Admin|Mobile]\Test;
class MyController extends \Controller\[Front|Admin|Mobile]\Controller {
public function index() {
$this->redirect('../order/cart');
}
}