Welcome Guest, Not a member yet? Register   Sign In
Redirect to forward slash
#1

Hi all,

I am trying to understand CodeIgniter.
I am having the code, created by a developer, I cannot contact.

In one of the Views, the index functions looks like this:

PHP Code:
public function index()
  {
      redirect('/');
  

Can anyone tell me what is does and why it should be used? I was under the impression, that this means, that the View redirects to the Main.php controller in the folder, the View is located - but that doesn't make sense. So what am I missing??

Albert
Reply
#2

(This post was last modified: 02-04-2021, 03:13 AM by captain-sensible.)

it may seem clearer if you look at in the context of a route in Routes.php :

this is one of my routes:

Code:
$routes->get('/', 'Home::index');



put simply that will take affect with a url such as https://someDomain.com .

Home is the name of the controller and index is the default method within the controller "home".

Quote:In one of the Views, the index functions looks like this:

surely you mean in one of the controllers, the code looks like ...


Code:
public function index()
  {
      redirect('/');
  }


so to elaborate, if the function index() in some controller is evoked redirect('/') basically means re-direct to the
route '/'

what happens next depends on whether a route for '/' is defined. in my case as i said mine is set up as:
Code:
$routes->get('/', 'Home::index');

my function index in controller home just loads a view called "home" .
Reply




Theme © iAndrew 2016 - Forum software by © MyBB