2014-02-28 4 views
0

두 개의 컨트롤러 인 InvoicesController.php와 ProductsController.php가 있습니다. invoice_add.ctp 양식을 제출할 때 리디렉션해야하지만 step1에 데이터를 저장하지 마십시오. 데이터 저장은 2 단계에서 URL이 인 product_add.ctp/product_add? step = 2으로 저장됩니다. 내 코드는 .its 내 자식 URL https://github.com/vixy410/HeaderRedirectcakephp에서 헤더 리다이렉트 설정하기

InvoicesController.php

<?php 
App::uses('AppController', 'Controller'); 
App::uses('ProductController', 'Controller'); 

class InvoicesController extends AppController { 


public $components = array('Paginator'); 



    public function beforeRender() { 
     parent::beforeRender(); 
     $step = 1; 
     $this->set(compact('step')); 
     $step = $this->request->param('step'); 
     $this->invoice_add(); 
    } 

    public function invoice_add(){ 

     if($this->request->data('step1')){ 
      $this->response->header(array(
       'Location'=>array(
        'controller'=>'products', 
        'action'=>'product_add', 
        '?'=>array(
         'step'=>'2' 
        ) 
       ) 
      )); 
     } 
     else{ 

      } 
     } 

//Element/step1.ctp

를 리디렉션하지 이하

<div class="invoices form"> 
<?php echo $this->Form->create('Invoice',array(
    'url'=>array('controller'=>'invoices','action'=>'invoice_add') 
)); ?> 
<fieldset> 
    <legend><?php echo __('Add Invoice'); ?></legend> 
<?php 
    echo $this->Form->input('client_name'); 
    echo $this->Form->input('client_email'); 
    echo $this->Form->input('phone'); 
      echo $this->Form->submit('Next Step',array('name'=>'data[Invoice][step1]')); 
?> 
</fieldset> 
<?php echo $this->Form->end(); ?> 
</div> 
<div class="actions"> 
<h3><?php echo __('Actions'); ?></h3> 
<ul> 

    <li><?php echo $this->Html->link(__('List Invoices'), array('action' => 'index')); ?></li> 
</ul> 
</div> 

// 요소/step2.ctp

보기/송장에서 10

//invoice_add.ctp

<div class="container"> 
<?php 
    if($step == 1){ 
     echo $this->element('step1'); 
    } 
    if($step == 2){ 
     echo $this->element('step2'); 
    } 

?> 
</div> 

답변

0

당신이 Controller::redirect()를 사용하지 않는 이유는 특정 이유가 있나요?

는 헤더를 설정 한 후

$this->response->send(); 

을보십시오. 그러나 당신의 코드는 redirect()가 이미하는 일의 바퀴를 새롭게 만든다.

+0

$ this-> response-> header() 대신 $ this-> response-> send()를 사용합니다. – Vikky

관련 문제