Welcome Guest, Not a member yet? Register   Sign In
Default Method in Controller (... index() ... ? )
#1

[eluser]beneck[/eluser]
I am having a little bit of trouble accessing a method and I am out of idea.

The method is called index() and it's in a Controller called Screen.

I can access the file correctly via:
http://site/screen/index

However, if I do not want to have to put the "index" on there, and I try to access it (assuming the default index() method will be called) by typing
http://site/screen

I get a bunch of CI errors followed by a 404 Page.

Is the index() method called by default if no method is put in the URL?

Here is my controller file
Code:
class Screen extends CI_Controller
{
   public function __construct()
   {
      parent::__construct();
   }

   public function index()
   {
      $this->load->view('screening/index');
   }
}

Here is my .HTACCESS file (perhaps I do not have the property code?)

Code:
RewriteEngine On
  RewriteBase /
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^(.*)$ index.php?/$1 [L]
#2

[eluser]InsiteFX[/eluser]
Try this.

Code:
Options +FollowSymLinks
Options -Indexes

DirectoryIndex index.php

RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
#3

[eluser]beneck[/eluser]
I appreciate your response! Smile


Unfortunately however, that did not work. Sad
#4

[eluser]InsiteFX[/eluser]
I would check your base_url in config.php looks like your paths are messed up some place.

It will also depend on what you have done with your index.php file in the config.php
#5

[eluser]beneck[/eluser]
Thank you for your help.

Ultimately I think I decided I was just trying to make the index method call without the index method being present in the URL and without having to use the routes file.

I just added it to the routes file and it's working fine. I think once the site is closer to being ready to launch I'll write a hook function that looks at the URI and determines if we are in a controller that does not have a method present and then make index the default method.

This way if I wanted http://site.com/folder/controller/

Then it would redirect with a hook to folder->controller->index method.

Just for FYI...

In my config.php file

Code:
$config['base_url'] = '';
$config['index_page'] = '';

We leave the base_url empty because we have several different programmers from all over the globe working on the site, so they are setting it explicitly in their environment on the index.php file.

But I think the correct answer was that I just need to explicitly route the non-index method calling URL internally to call the index method via the routes.php file and then eventually use a hook to fix it to do what I want.

Again, your help is appreciated. Thank you.




Theme © iAndrew 2016 - Forum software by © MyBB