We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Redirect not working right : Or, today's newbie question

public function saveAction( $reportType, $clientId, $date )
{
    return $this->response->redirect('report/list/' . $reportType . '/' . $clientId);        
}

End up here:

mydomain.com/index.phpreport/list/da/178

Putting a leading slash in front of report did not help. I'm worried I config'd something wrong.

Do I need to edit the apache setup to remove index.php from the url?

Yes to your question about apache setup.

Hi @driscojs you have to begin with "/"

public function saveAction( $reportType, $clientId, $date )
{
    return $this->response->redirect('/report/list/' . $reportType . '/' . $clientId);        
}

or better use url service

return $this->response->redirect($this->url->get(['controller' => 'foo', 'action' => 'bar', 'for' => 'baz']));        

Good luck



6.6k

I did try the leading slash, no luck.

I don't understand the 'for' in the array. I checked the docs, but I'm sure what it's for.

Hi @driscojs you have to begin with "/"

public function saveAction( $reportType, $clientId, $date ) { return $this->response->redirect('/report/list/' . $reportType . '/' . $clientId);
}

or better use url service

return $this->response->redirect($this->url->get(['controller' => 'foo', 'action' => 'bar', 'for' => 'baz']));

Good luck



6.6k

index.php is only showing up in the attempt to redirect, but not when using relative URLs in my Views. Is that going to be a problem? It seems like Phalcon is smart enough to figure out the URL from relative HREFs, but not when doing a redirect. Makes me think my routing might be off?

Yes to your question about apache setup.



5.1k

Three questions but same to be sure :

  • report is your controller name or your module name ?
  • list is your action name or controller name ?
  • $reportType and $clientId are parameters ?


6.6k

Yep, report is the controller, list is the listAction function, and $reportType and $clientId are parameters I'm trying to pass (they are set, I confirmed.)

Three questions but same to be sure :

  • report is your controller name or your module name ?
  • list is your action name or controller name ?
  • $reportType and $clientId are parameters ?


5.1k

I suspect this is the relative path between your application and your site home directory

in first time to load your application you use https://mydomain.com ? or more after ?

or https://mydomain.com/public ? in this case you put .htaccess like this in project folder ?


<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteRule ^$ public/     [L]
    RewriteRule (.*) public/$1 [L]
</IfModule>

good luck

for attribute is for named routes ;)

I did try the leading slash, no luck.

I don't understand the 'for' in the array. I checked the docs, but I'm sure what it's for.

Hi @driscojs you have to begin with "/"

public function saveAction( $reportType, $clientId, $date ) { return $this->response->redirect('/report/list/' . $reportType . '/' . $clientId);
}

or better use url service

return $this->response->redirect($this->url->get(['controller' => 'foo', 'action' => 'bar', 'for' => 'baz']));

Good luck