Zend Yönlendirme

0 Cevap php

Bu gerekiyordu değil zaman nedense benim zend uygulama yönlendiriliyor.

Dizin görünümü sadece form gösterir. Sonraki görünümü form tarafından sağlanan bilgilere dayalı bir veritabanından bazı bilgileri gösterir. Kullanıcı daha sonra bir e-posta oluşturur ve gönderir anotherAction gönderir bir onaylama butonuna tıklar. Ben e-posta göndermek için çalışan bir try / catch bloğu var. Başarılı, bir değişkeni ayarlamak, aksi takdirde başka bir set.

Psudo-kodu:

public function indexAction()
{
 $form = new Form();
 if(!empty($_POST))
 {
  if($form->isValid($_POST))
  {
   $this->_helper->FlashMessenger($_POST); //store $_POST in temporary session
   //show a different view
   //do something else
  }
 }
$this->view->form = $form;
}

Kullanıcı mesaj formu daha sonra bunu doğrulamak ve bir flaş oturumda oturum değişkenleri depolamak ve bir differnet görünümü göstermek Yani ben, bir form instantialising ediyorum. Tüm durumlarda (o gönderilmiş olması halinde, otomatik olarak doldurulur olacak) form gösterirler.

public function anotherAction()
{
 $messages = $this->_helper->FlashMessenger->getMessages();
 if (!empty($messages[0]))
 {
  $post = $messages[0];
  $mail = new My_Mail();
  //set up email
  try
  {
   $mail->send();
   $success = true;
  }
  catch (Zend_Exception $e)
  {
   $success=false;
   //save $e to log
  }
  $this->view->success = $success;
 }
 else
 {
  //if not sent here by /page, then redirect to it.
  $this->_helper->redirector->goToRouteAndExit(array(), 'page', true);
 }
}

Bu eylem, ben oturumu için kontrol ediyorum. Bunun içinde form verilerini var ise, o zaman bir e-posta ve set değişkeni göndermek için çalışın; aksi takdirde geri forma yönlendirmek. Görünümü değişken bir mesaj ya da diğer (e-posta gönderildi / email göndermek için başarısız) göstermek için kullanılır.

İşte sorun: Bu zaten geri forma yönlendirir. Form teslim ve teyit edilir, biz o zaman bunun üzerinde formu ile geri sayfaya yönlendirir bir şey yapar bir sonraki sayfaya gidin. Neden bunu yapıyor ve bunu nasıl durdurabilirim?

[edit] The plot thickens: If I open the confirm link in a new tab it will run and stop correctly. If I do it in the same tab/window it runs twice and redirects.

[another edit] I have removed all the code in the second action. The code is now:

public function anotherAction()
{
 $messages = $this->_helper->FlashMessenger->getMessages();
 if (!empty($messages[0]))
 {
  ;
 }
 else
 {
  $this->_helper->redirector->goToRouteAndExit(array(), 'page', true);
 }
}

ve hala yönlendiriliyor.

Ben onayla butonu için

<a href="next-page"><button>Confirm</button></a>

Çapa ve düğme sonraki sayfayı çağıran olabilir hem de?

[final edit] Ok, this IS the problem. It looks like both the button and the anchor are calling the page! So the first time it runs it's ok then it runs again and redirects me :(

Peki, oraya gidiyoruz. Gün yeni bir şey öğrenin.

Yardım Herşey için teşekkürler.

0 Cevap