CodeIgniter Forums
issue with controllers Help!!! :( - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forum-21.html)
+--- Thread: issue with controllers Help!!! :( (/thread-25701.html)

Pages: 1 2


issue with controllers Help!!! :( - El Forum - 12-21-2009

[eluser]LeonardoRaygoza[/eluser]
Hi, I'm having a problem because I created a new controller with a simple function called hello, with just a function index(), but it's appear like it doesn't run right.

my controller name is: blog
my code is:

<?php
class Blog extends Controller
{
function index()
{
echo "Hello world!";
}
}
?>

I tryied to check it on my server with my domain for example: http://www.leonardoraygoza.com/blog/

it suppouse show Hello world!

on my localhost it works! but on my web server it doesn't

I have on my config file system > application > config > config.php

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

$config['base_url'] = "http://leonardoraygoza.com/"; //webserver

so I don't know where I'm wrong :'( can please somebody help me


issue with controllers Help!!! :( - El Forum - 12-21-2009

[eluser]überfuzz[/eluser]
Did you set up the routes.php htaccess etc?


issue with controllers Help!!! :( - El Forum - 12-21-2009

[eluser]LeonardoRaygoza[/eluser]
yes I have on routers.php

$route['default_controller'] = "blog";

I don't have an htaccess, so I'm trying to access http://leonardoraygoza.com/index.php/blog/

but it doesn't works Sad


issue with controllers Help!!! :( - El Forum - 12-21-2009

[eluser]eoinmcg[/eluser]
What errors are you getting on your webserver?

You're controller isn't called Blog.php by any chance? A common pitfall is moving from a windows development environment to a live *nix one and forgetting that *nix filenames are case sensitive whereas on windows this isn't the case.


issue with controllers Help!!! :( - El Forum - 12-21-2009

[eluser]BrianDHall[/eluser]
Also, index.php/blog I believe only works when mod_rewrite is turned on in apache, otherwise your server will say "Huh, there is no directory called index.php with a directory inside it named blog, error!"

In your config.php you can try turning on query strings and use its suggested syntax, which I believe is http://leonardoraygoza.com/index.php?c=blog&m=index

If that works then your problem is related to your webserver, or your CI uri_protocol setting in config.php.

What sort of 404 is your server returning? If it is the regular 404 you are use to seeing elsewhere on the internet, it is a server configuration issue. If it is CI's custom 404, then it is a setting in your configuration of CI.


issue with controllers Help!!! :( - El Forum - 12-21-2009

[eluser]LeonardoRaygoza[/eluser]
well I'm not really sure what was the issue I just delete the system folder of my webserver and upload it again and it works! hehe

thx everybody for help! Smile


issue with controllers Help!!! :( - El Forum - 12-21-2009

[eluser]wiredesignz[/eluser]
[quote author="BrianDHall" date="1261445017"]Also, index.php/blog I believe only works when mod_rewrite is turned on in apache, otherwise your server will say "Huh, there is no directory called index.php with a directory inside it named blog, error!"[/quote]

@BrianDHall, Please stop telling people this, it is totally incorrect. mod_rewrite is not required to run a basic CodeIgniter installation.


issue with controllers Help!!! :( - El Forum - 12-21-2009

[eluser]BrianDHall[/eluser]
That can happen, when all else failes delete everything and start over Wink


issue with controllers Help!!! :( - El Forum - 12-21-2009

[eluser]DJMOHNL[/eluser]
if you make a controller try my template:

i have an editor called PHPdeisgner 7
its realy cool designer for php, with autocomplete and templates you can make.
Look this fill it in with your class name and function name..

the example template below shows you the function/cass name "Test" rename "Test" to your function/class name and you have a new controller...

Code:
<?php

// Here "Test" must be capitalised and uniqe controler name.
// There must be a function to load the parent with the same name of extended controller
class Test extends Controller {

        // Note this function must have the same name as the controller!
        // This loads al files you need, it will also load the parent::Controller you
        // just extended with the name "Test"
    function Test()
    {
        parent::Controller();
        // Below here you load libraries, helpers, configuration files and so on.
                $this->load->helper('myhelper'); // example
            
    }
    
    // on opening  www.yoursite.com/controlername/index*
        // * index wont show in your adress bar.
    function index()
    {
        // Load all (html/php) view files

                $this->load->view('myHeaderTemplate');
                $this->load->view('myViewFile');        
                $this->load->view('myFooterTemplate');
        
        
    }
        
        // Here you make new functions a.k.a url-loade
        // will be shown as: http://yoursite.com/test/namehere
        function namehere()
        {
          // your code goes here...
        }
}

/* End of file */
/* Location: ./system/application/controllers/test.php */

good luck with it.


issue with controllers Help!!! :( - El Forum - 12-21-2009

[eluser]CI_avatar[/eluser]
you did not initialize your controller

Code:
class Blog extends Controller
{
   //you missed this one
   //function Blog()
   //{
   //   parent::Controller();    
   //}

   function index()
   {
      echo “Hello world!”;      
   }
}