• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
index function in Controller not working

#1
[eluser]eberth[/eluser]
Hello, I am experiencing something very strange, the index function in my default controller is not being loaded automatically when accessing the controller, is there some new setting i have to change in order to reactivate the default funcionallity of the controller or is this a bug?

thanks for your help.

#2
[eluser]CroNiX[/eluser]
post the code. The "index" function will only be called if no method is in the url for that controller, or it is explicitly called. If you want something to execute no matter what method is being called, you do that in the class constructor.

yoursite.com/cool_controller
this will call the index method of cool_controller

yoursite.com/cool_controller/index
so will this

yoursite.com/cool_controller/other_method
index will not be called here

#3
[eluser]eberth[/eluser]
Yeah, thats how it should work, but i dont know why it only works when loading the index function explicitly

You can check it out on:

http://pruebas.overflow.mx/ricoy doesnt work

But

http://pruebas.overflow.mx/ricoy/index Works

This has never happened to me before, i've always used CI 1.7, and its the first time im using reactor, so i guess this might be a bug


Which part of the code do you want me to post? The controller?

Thank you

#4
[eluser]eberth[/eluser]
Oh btw i modified the routes file in order to always load the default controller , so ricoy is only a directory and the default controller is site

Here is what the system logs when you load the controller alone


ERROR - 2011-04-15 06:09:15 --> 404 Page Not Found --> site/
ERROR - 2011-04-15 06:55:27 --> 404 Page Not Found --> site/

#5
[eluser]eberth[/eluser]
here is my Site controller


Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Site extends CI_Controller {

    function __construct()
    {
        parent::__construct();
    }

   function index()
    {
        $data = array(
          'title' => 'Ricoy Bienes Raíces :: Terrenos, Departamentos, Casas y Residencias',
          'content' => 'inicio'
          );
        
        $this->load->view('_template', $data);
    }
    
    
    
    function propiedades()
    {
        $data = array(
          'title' => 'Ricoy Bienes Raíces :: Terrenos, Departamentos, Casas y Residencias',
          'content' => 'propiedades'
          );
        
        $this->load->view('_template', $data);
    }
    
    function servicios()
    {
        $data = array(
          'title' => 'Ricoy Bienes Raíces :: Terrenos, Departamentos, Casas y Residencias',
          'content' => 'servicios'
          );
        
        $this->load->view('_template', $data);
    }
    
    function contacto()
    {
        $data = array(
          'title' => 'Ricoy Bienes Raíces :: Terrenos, Departamentos, Casas y Residencias',
          'content' => 'contacto'
          );
        
        $this->load->view('_template', $data);
    }
    
    
    
}

#6
[eluser]eberth[/eluser]
I am making some experiments,

I created another controller that only has the index function, which loads the home controller... it works as it should, no need to explicitly put index in the url in order to load.... so i changed my default controller to this test one and boom, it suddenly stopped working, so i guess it has something to do with the routes ,

This route is what i´ve always used to remove the controller from the url,

Code:
$route['^(?!formas|archivos).*'] = "site/$0";

and the .htaccess i´m using to remove the index.php

Code:
<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_URI} ^/system.*
    RewriteRule ^(.*)$ index.php?/$1 [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.+)$ index.php?/$1 [L]
</IfModule>

somehow i think this is messing it up, any clue?

#7
[eluser]InsiteFX[/eluser]
Well if you think it is messing it up! Take it out and see if it works...

InsiteFX

#8
[eluser]toopay[/eluser]
[quote author="eberth" date="1302898591"]
This route is what i´ve always used to remove the controller from the url,
Code:
$route['^(?!formas|archivos).*'] = "site/$0";
[/quote]

Why you ALWAYS remove the controller from the url?? What for?
[quote author="eberth" date="1302898591"]
and the .htaccess i´m using to remove the index.php

Code:
<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_URI} ^/system.*
    RewriteRule ^(.*)$ index.php?/$1 [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.+)$ index.php?/$1 [L]
</IfModule>
[/quote]
for .htaccess, this ussually working in (almost) any situation :
Code:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*) index.php?/$1


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.