2010年10月22日星期五

Re: [fw-mvc] Referer

-- Jigal sanders <jigalroecha@gmail.com> wrote
(on Friday, 22 October 2010, 05:12 PM +0200):
> Well from user/edit i am redirected to user/login
>
> In the login action i do:
>
> $origin = $this->request()->getHeader('referer');
> var_dump($origin);
>
> And it gives me:
>
> index/index
>
> But i expect
>
> user/edit

Ooops, my bad; you need to store the page that sent you to the login
form:

// on login page:
$referer = $this->getRequest()->getHeader('referer');
// don't forget to sanitize the referer and ensure it goes to a page
// on your site!

$session = new Zend_Session_Namespace('login');
$session->referer = $referer;

Then, after successful login:

$session = new Zend_Session_Namespace('login');
$referer = $session->referer;
if (empty($referer)) {
$referer = /* some default page */;
}
return $this->_redirect($referer);

> On Fri, Oct 22, 2010 at 4:58 PM, Matthew Weier O'Phinney
> <matthew@zend.com>wrote:
>
> > -- Jigal sanders <jigalroecha@gmail.com> wrote
> > (on Friday, 22 October 2010, 04:48 PM +0200):
> > > This is more of an architectual question which should lead for me to a
> > > development decision.
> > > I sometimes in my application have some links. But in order to see what's
> > > behind the links you have to be logged in. So the user is redirected to a
> > > login page.
> > > But I want the user to be redirected to the original page after he has
> > > logged in.
> > >
> > > What's the best way to implement this in a zf based site?
> >
> > Grab the referer from the request object:
> >
> > // In an action method of a controller
> > $request = $this->getRequest();
> > if (/* some op succeeded */) {
> > $origin = $request->getHeader('referer');
> > return $this->_redirect($origin);
> > }
> >
> > That's really all there is to it.
> >
> > --
> > Matthew Weier O'Phinney
> > Project Lead | matthew@zend.com
> > Zend Framework | http://framework.zend.com/
> > PGP key: http://framework.zend.com/zf-matthew-pgp-key.asc
> >
>
>
>
> --
> Met vriendelijke groet,
>
> Jigal Sanders
> A.J. Ernststraat 739
> 1082 LK Amsterdam
> Mobiel: 06-42111489

--
Matthew Weier O'Phinney
Project Lead | matthew@zend.com
Zend Framework | http://framework.zend.com/
PGP key: http://framework.zend.com/zf-matthew-pgp-key.asc

Re: [fw-mvc] Referer

-- Matthew Weier O'Phinney <matthew@zend.com> wrote
(on Friday, 22 October 2010, 10:58 AM -0400):
> -- Jigal sanders <jigalroecha@gmail.com> wrote
> (on Friday, 22 October 2010, 04:48 PM +0200):
> > This is more of an architectual question which should lead for me to a
> > development decision.
> > I sometimes in my application have some links. But in order to see what's
> > behind the links you have to be logged in. So the user is redirected to a
> > login page.
> > But I want the user to be redirected to the original page after he has
> > logged in.
> >
> > What's the best way to implement this in a zf based site?
>
> Grab the referer from the request object:
>
> // In an action method of a controller
> $request = $this->getRequest();
> if (/* some op succeeded */) {
> $origin = $request->getHeader('referer');
> return $this->_redirect($origin);
> }
>
> That's really all there is to it.

One thing: somebody asked me to point out that you shouldn't blindly
trust the Referer header, which is an excellent point to make. Run it
through a regexp, and ensure it's actually heading back to *your* site.
:)

--
Matthew Weier O'Phinney
Project Lead | matthew@zend.com
Zend Framework | http://framework.zend.com/
PGP key: http://framework.zend.com/zf-matthew-pgp-key.asc

Re: [fw-mvc] Referer

Well from user/edit i am redirected to user/login

In the login action i do:

$origin = $this->request()->getHeader('referer');
var_dump($origin);

And it gives me:

index/index

But i expect

user/edit

On Fri, Oct 22, 2010 at 4:58 PM, Matthew Weier O'Phinney
<matthew@zend.com>wrote:

> -- Jigal sanders <jigalroecha@gmail.com> wrote
> (on Friday, 22 October 2010, 04:48 PM +0200):
> > This is more of an architectual question which should lead for me to a
> > development decision.
> > I sometimes in my application have some links. But in order to see what's
> > behind the links you have to be logged in. So the user is redirected to a
> > login page.
> > But I want the user to be redirected to the original page after he has
> > logged in.
> >
> > What's the best way to implement this in a zf based site?
>
> Grab the referer from the request object:
>
> // In an action method of a controller
> $request = $this->getRequest();
> if (/* some op succeeded */) {
> $origin = $request->getHeader('referer');
> return $this->_redirect($origin);
> }
>
> That's really all there is to it.
>
> --
> Matthew Weier O'Phinney
> Project Lead | matthew@zend.com
> Zend Framework | http://framework.zend.com/
> PGP key: http://framework.zend.com/zf-matthew-pgp-key.asc
>

--
Met vriendelijke groet,

Jigal Sanders
A.J. Ernststraat 739
1082 LK Amsterdam
Mobiel: 06-42111489

Re: [fw-mvc] Referer

-- Jigal sanders <jigalroecha@gmail.com> wrote
(on Friday, 22 October 2010, 04:48 PM +0200):
> This is more of an architectual question which should lead for me to a
> development decision.
> I sometimes in my application have some links. But in order to see what's
> behind the links you have to be logged in. So the user is redirected to a
> login page.
> But I want the user to be redirected to the original page after he has
> logged in.
>
> What's the best way to implement this in a zf based site?

Grab the referer from the request object:

// In an action method of a controller
$request = $this->getRequest();
if (/* some op succeeded */) {
$origin = $request->getHeader('referer');
return $this->_redirect($origin);
}

That's really all there is to it.

--
Matthew Weier O'Phinney
Project Lead | matthew@zend.com
Zend Framework | http://framework.zend.com/
PGP key: http://framework.zend.com/zf-matthew-pgp-key.asc

[fw-mvc] Referer

Hello,

This is more of an architectual question which should lead for me to a
development decision.
I sometimes in my application have some links. But in order to see what's
behind the links you have to be logged in. So the user is redirected to a
login page.
But I want the user to be redirected to the original page after he has
logged in.

What's the best way to implement this in a zf based site?

Looking forward to your suggestions and links to existing tutorials.

J. Sanders

2010年10月21日星期四

Re: [fw-mvc] Passing Array from One Controller to Another

Flash messenger isn't a bad idea. It's already designed to work within
controllers and has a built-in auto-destroy feature after 1 hop. It also
supports arrays or objects that can be serialized.

So if you're redirecting, the first request would set the data:

$myArray = array(/* ... */);
$this->_helper->flashMessenger->addMessage($myArray);

In the following request you can pull it:

$messages = $this->_helper->flashMessenger->getMessages();
$myArray = $messages[0];

--
*Hector Virgen*
Sr. Web Developer
Walt Disney Parks and Resorts Online
http://www.virgentech.com

Re: [fw-mvc] Passing Array from One Controller to Another

Alternatively, ignore me as I noticed you want to pass an array.

G

On 21 October 2010 17:57, Gary Hockin <gary@garyhockin.co.uk> wrote:

> Take a look at the Flash Messenger action helper...
>
> http://framework.zend.com/manual/en/zend.controller.actionhelpers.html
>
> Gary/Spabby
>
>
> On 21 October 2010 17:49, Thomas List <thomaslist@hotmail.com> wrote:
>
>>
>> I've been trying to pass an array from one Controller to another without
>> any luck. I've tried to use the Zend_Registry, but when I try to retrieve
>> the value in the next Controller, I get an error "No entry is registered for
>> key 'resultsAdmin'". So how is this done without resorting to redirects and
>> such? I've tried using Zend_Session_Namespace(), but can't find any answers
>> as to how to retrieve the value from the Namespace() once it is set. There
>> has to be a way to create a globalized variable and access it, but how is it
>> done in Zend?
>>
>> Thomas List
>>
>
>
>