Welcome Guest, Not a member yet? Register   Sign In
Problem calling controller functions
#1

[eluser]Unknown[/eluser]
Hi

I'm new to using CI but I'm loving it, however I have a small problem.

I've developed a single page application locally using MAMP and I've just uploaded it for testing on a remote server. The remote server is using php 5.2.1

I've set the default controller in the routes config file & I've set the $config['base_url'] correctly.

If I use http://my_domain.com/index.php or http://my_domain.com the page loads correctly, but if I try to call a function within the controller I am getting a 500 Internal Server Error.

I've tried to create a simple controller just to test it and I'm getting the same problem.

Here's what I've done to test.

Changed the default controller to: testcontroller

Created a controller called: testcontroller.php

Code:
<?php

class Testcontroller extends Controller {

    function Testcontroller()
    {
        parent::Controller();
    }
    
    function index(){
        echo "Index Called";
    }
    
    function functioncalled(){
        echo "Function Called";
    }
    
    
}
?>

Now if I go to
http://my_domain.com/index.php or
http://my_domain.com I get a page that shows "Index Called".

If I go to http://my_domain.com/index.php/testcontroller
or http://my_domain.com/index.php/testcontr...tioncalled
or http://my_domain.com/index.php/testcontr...ioncalled/
etc I'm getting the Internal Server Error.

Am I overlooking something? Its been a long week Big Grin

Thanks

Carl
#2

[eluser]prestondocks[/eluser]
Hi Carl,

I cant see anything wrong with the code you pasted here so it may be a problem with your config file.

Try another default install of CI into another folder and use the welcome controller to test. Also the only thing you should need to change in config to get a very basic system working is the base_url

Hope this helps
#3

[eluser]Unknown[/eluser]
Mmm…

I've installed a fresh install of CodeIgniter_1.7.2 in a directory called testinstall. Set the config to $config['base_url'] = "http://my_domain.com/testinstall/

Now I'm getting the error "Disallowed Key Characters".

I've hacked an input.php function to find out what character is causing the error
Code:
function _clean_input_keys($str)
{
if ( ! preg_match("/^[a-z0-9:_\/-]+$/i", $str))
{
exit('Disallowed Key Characters: '.$str); // Added the variable to display.
}

return $str;
}

and discovered that its a # character.

Adding the # into the regex
Code:
[#a-z0-9:_\/-]
allows me to get past his error but I'd rather not do that.

Now if I go to http://my_domain.com/testinstall all is well.

However if I try to call a function directly I get the Internal Server Error.

Am I calling the function correctly?

http://my_domain.com/testinstall/index.p...ome/callme

Code:
<?php

class Welcome extends Controller {

    function Welcome()
    {
        parent::Controller();    
    }
    
    function index()
    {    
        $this->load->view('welcome_message');
    }
    
    function callme(){
        echo "This function has been called";
    }
}

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


Thanks

Carl




Theme © iAndrew 2016 - Forum software by © MyBB