My redirect function is not working in codeigniter

2019-09-02 20:02发布

问题:

I have the following code:

$this->video->videoupdate($userid, $title, $id);
redirect("admin/videos", "refresh");

But the redirect is not working and I don't know why (I am using CodeIgniter)

回答1:

Have you sent anything to the browser prior to calling redirect? From the user guide

Note: In order for this function to work it must be used before anything is outputted to the browser since it utilizes server headers.



回答2:

have you loaded the URL helper?

$this->load->helper('url');

Load this in your controller. I usually put mine either in the constructor or the autoload config.



回答3:

try this :

redirect("admin/videos");

without "refresh"



回答4:

  1. Remove the echo if any above redirect
  2. Check your htaccess, write like this:

    RewriteEngine on
    RewriteCond $1 !^(index\.php|images|assets|robots\.txt)
    RewriteBase /sitename/
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d``
    RewriteRule ^(.*)$ /index.php [L]
    


回答5:

I have just fixed it with this ->

$config['base_url'] = 'http://localhost:3000/';

So apparently you must define this before use your url helper.