Zend Framework Application Progress

Today I learned from Zend Framework.

Redirecting visitors to their intended URI after login

LoginForm.php

  ...
  // Grabs the requested URI from the server and stores it in a hidden field
  $this->addElement('hidden', 'referrer', array('value' => $_SERVER['REQUEST_URI']));
  ...

Then after you complete authentication, send them to the referring URI

  if($form->getValue('referrer'))
      $this->_redirect($form->getValue('referrer'));
  $this->_redirect('index/index');

Credits:
http://stackoverflow.com/questions/1249274/redirect-to-previous-page-in-...


Throwing an error message

This one is easy. You want to throw an error message with some meaning.

  throw new Zend_Exception('This is the error message');


Saving data in Zend_Session

You want to save some data in a session variable so you can access it other places in application. So in the Bootstrap.php file you would place

  Zend_Session::start();

To set the variable you would use

  $ns = new Zend_Session_Namespace('hello');
  $ns->domain = "Hello World";

By using the namespace "hello" or whatever you want, then you can keep your variables separate from another part of the applicate that just might happen to name it's variable "domain" as well.

To retrieve this fun filled variable.

  $ns = new Zend_Session_Namespace('hello');
  print $ns->domain;

Comments

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.
  • Web page addresses and e-mail addresses turn into links automatically.
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <drupal5>, <drupal6>, <javascript>, <php>, <sql>. Beside the tag style "<foo>" it is also possible to use "[foo]".

More information about formatting options