Zend: WTF

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Zend: WTF

Post by alex.barylski »

Code: Select all

$http = new Zend_Http_Client();

// Set the URI to a POST data processor
$http->setUri('http://localhost/xampp/?page=postad');
$http->setHeaders(array('Location: http://localhost/xampp/?page=post'));

// ... $postData is initialized properly from the examples in Zend

$http->post($postData); // Execute HTTP request and redirect
Anybody care to tell me why the above code wouldn't redirect? I'm missing something...and it's driving me nutts :?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Http_Client is their browser class. Why would a browser send a server a Location header? :D
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Post by alex.barylski »

feyd wrote:Http_Client is their browser class. Why would a browser send a server a Location header? :D
So how would I send a script POST contents and then redirect to that script?

Basically:
index.php --> somescript.php --> index.php
Index.php has a form which is submitted to somescript.php which checks validity, etc and redirects back to index.php (POSTING data for persistence) if anything goes wrong to allow corrections???

Could I use this class and header()???

Cheers :)
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

If I read their documentation correctly the posted-to page redirecting would be followed (under defaults) provided it was a header redirection.
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Post by alex.barylski »

feyd wrote:If I read their documentation correctly the posted-to page redirecting would be followed (under defaults) provided it was a header redirection.
I'm missing something...

http://framework.zend.com/manual/en/zen ... ttp.client

Where in that doc does it have an example of posted-to page??? :oops:

edit: sorry dude...but i'm growing impatient...I wanted this to just work...not interested in d*cking aorund :P
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Hockey wrote:I'm missing something...

http://framework.zend.com/manual/en/zen ... ttp.client

Where in that doc does it have an example of posted-to page??? :oops:
You didn't miss anything much, they don't have an example. The text I was referring to is:
Introduction wrote:Zend_Http_Client follows up to 5 HTTP redirections by default. To change this behavior, pass the maximum number of allowed redirections to the get() method.
That suggested to me that it would follow a redirection sent for any request. If it doesn't, I would consider the documentation misleading.
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

Post by Ollie Saunders »

$this->_redirect
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Post by alex.barylski »

ole wrote:$this->_redirect
By convention, it appears any members with leading underscore are protected or private which mean I can't access them as you've suggested... :P

Cheers
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

Post by Ollie Saunders »

Code: Select all

class BlahControllers extends Zend_Controller_Action // i think that's what its called
{
    public function someAction()
    {
        $this->_redirect('yay!');
    }
}
ole is attempting to talk purely in php code :P
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Post by alex.barylski »

I'm still lost... :P

For starters I'm not using any of the Zend classes except for Zend_Http_Client and it's required base class(es).

I'm posting data and need to redirect POST data back to the original script...
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Post by alex.barylski »

Apparently, what I'm trying to do is quite the hack show...

Basically, redirection in response to a POST has a lot of caveats :?
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

Post by Ollie Saunders »

For starters I'm not using any of the Zend classes except for Zend_Http_Client and it's required base class(es).
Oh right, well then you'll have to do the redirect manually with header as per normal.
Anybody care to tell me why the above code wouldn't redirect?
Can you define exactly what you mean by that. Allow the Http_Client to accept a redirection and make a second request or redirect your code to another file?
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Post by alex.barylski »

I haven't tried, but I don't think a normal redirect would work...as I'm not redirecting perse, but rather posting the data back to the original FORM and redirecting back to the original FORM...

Emulating postback...

Not just, POST data to script, which is easy, but POST data to script & redirect

Using a normal redirect using header() would likely do something like:

1) Send POST data to original script
2) Redirect back to original script - but without post data

So the original script would be executed twice, where first it receives the POSTed data and then it's executed again but just displays the FORM empty...

I need to carry out the process concurrently so when the page is requested the POST data is displayed in the FORM elements...

Any ideas? I think I'm on the right track, but I'd love to hear a solution immediately and not have to wade through the RFC for HTTP and it's status codes... :P
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

Post by Ollie Saunders »

Not just, POST data to script, which is easy, but POST data to script & redirect
Ah in which case you can forget everything I have said in this thread thus far. Oh and I don't know how to do that so sorry I can't help anymore.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Hockey wrote:I need to carry out the process concurrently so when the page is requested the POST data is displayed in the FORM elements...
This bit doesn't make sense. Grammatically I can't figure out what specifically you mean.
Post Reply