Aura.Web Problems with $response->redirect

20 views
Skip to first unread message

Goofus Insanius

unread,
Jan 15, 2016, 10:18:09 AM1/15/16
to The Aura Project for PHP
Hello,

I'm using Aura.Web and am trying to redirect a user to another page within the website.

At the end of my bootstrap.php i have the following:


<?php
// send status line
header($response->status->get(), true, $response->status->getCode());

// send non-cookie headers
foreach ($response->headers->get() as $label => $value) {
    header("{$label}: {$value}");
}

// send cookies
foreach ($response->cookies->get() as $name => $cookie) {
    setcookie(
        $name,
        $cookie['value'],
        $cookie['expire'],
        $cookie['path'],
        $cookie['domain'],
        $cookie['secure'],
        $cookie['httponly']
    );
}

// send content
echo $response->content->get();
?>

Within a controller i have:
$this->response->redirect->to( $slug, 302 );

This doesn't resolve it the expected behaviour.
When i debug:

echo $this->response->status->getCode()


I get a '200' instead of 302.

How do i fix this?

Hari K T

unread,
Jan 15, 2016, 11:01:52 AM1/15/16
to aur...@googlegroups.com
Hey,

I'm using Aura.Web and am trying to redirect a user to another page within the website.

At the end of my bootstrap.php i have the following:


<?php
// send status line
header($response->status->get(), true, $response->status->getCode());

// send non-cookie headers
foreach ($response->headers->get() as $label => $value) {
    header("{$label}: {$value}");
}

// send cookies
foreach ($response->cookies->get() as $name => $cookie) {
    setcookie(
        $name,
        $cookie['value'],
        $cookie['expire'],
        $cookie['path'],
        $cookie['domain'],
        $cookie['secure'],
        $cookie['httponly']
    );
}

// send content
echo $response->content->get();
?>


But that is not the problem here I assume.
 
Within a controller i have:
$this->response->redirect->to( $slug, 302 );

 
This doesn't resolve it the expected behaviour.
When i debug:

echo $this->response->status->getCode()


May I know how you are creating the response object ?

Is it via the same factory ?

It looks to me you are creating not via the Factory and passing different Status objects for the Redirect and the response Status.

Tested with

<?php
require __DIR__ . '/vendor/autoload.php';
use Aura\Web\WebFactory;

$web_factory = new WebFactory($GLOBALS);
$response = $web_factory->newResponse();

$response->redirect->to('/hello');
echo $response->status->getCode();
Reply all
Reply to author
Forward
0 new messages