Categories
Archives
Pages
My Tweet
- 電車のつり革にRarejobの広告が。今年当たりからオンライン英会話の普及が加速するか。 http://t.co/tbFEuMAV 2 days ago
- 勉強になったな〜。感謝です。 1 week ago
- 西武線の英語アナウンスで一カ所早すぎて聞き取れない箇所があって気になっていたんだが、こんなとこまで記事にしてくれた方が。 自動放送 西武線 http://t.co/99VsMAy2 2 weeks ago
- More updates...
Posting tweet...
Powered by Twitter Tools
Friend Links
[CakePHP]How to get View file name in element or layout
[cakephp 1.3.3]
I introduce how to get to know view name in element or layout that is specified by $this->render in controller.
For example, with the contact form, as seen below, many times with one action the view is specifed.
function contact() { //first view or return selected if (!empty($this->params['form']['return']) || empty($this->data)) { /* getting data required by form process */ } //confirm view or error view elseif (!empty($this->params['form']['confirm'])) { /* validating process */ $this->render('contact_confirm'); } //finish else { /* saving data process */ $this->render('contact_done'); } }But depending on the value of the view, there are times when I want to change the operation of element or layout.
At that time, if you render method override the app_controller, from the element or layout in $this->params[‘view’] you can subtract the value and it’s convenient.
function render($action = null, $layout = null, $file = null) { if ($action !== null) { $view = Inflector::underscore($action); } else { $view = Inflector::underscore($this->action); } $this->params['view'] = $view; if (!$controller = $this->params['controller']) { return false; } return parent::render($action, $layout, $file); }