Welcome Guest, Not a member yet? Register   Sign In
Problems with function call
#1

[eluser]Honscho[/eluser]
Hi there,

I am fairly new to CI and I am encountering an issue that I haven't had before.
I recently installed CI again for a project and for some strange reason I am not able to call another function via an URI segment.
I have set the route to:

Code:
$route['default_controller'] = "start";

In the Start controller I have the following code:
Code:
<?php

class Start extends Controller {

    function Start()
    {
        parent::Controller();    
        $this->load->helper('url');
    }
    
    function index()
    {
        $this->load->language("base", "english");
        $data['willkommen'] = $this->lang->line('lng_willkommen');
        $data['intro'] = $this->lang->line('lng_intro');
        $this->load->view('start_message', $data);
    }
    
    function test()
    {
        $this->load->language("base", "german");
        $data['willkommen'] = $this->lang->line('lng_willkommen');
        $data['intro'] = $this->lang->line('lng_intro');
        $this->load->view('start_message', $data);
    }
}

/* End of file start.php */
/* Location: ./system/application/controllerS/start.php */

Now, this URL will work:

http://localhost/foldername/
http://localhost/foldername/index.php

And those wont:

http://localhost/foldername/index.php/test (while this gives me the internal CI error 404)
http://localhost/foldername/test (this gives me the browsers error 404)

I assume that with the first error message I am still within CI and the second error I am getting an actual "document not found error".

I have done this before but for some stupid reason I am unable to find the mistake.

Anyone has an idea or a hint? Smile
I would be very happy for some advice!

Thanks in advance!
#2

[eluser]Honscho[/eluser]
Hm, now I am really confused.

How is this working:
http://localhost/foldername/index.php/blog/
http://localhost/foldername/index.php/blog/comments


Code:
<?php
class Blog extends Controller {

    function index()
    {
        echo 'Hello World!';
    }
    
    function comments()
    {
        echo 'Look at this!';
    }
}
?>

But my example in the previous post not?
#3

[eluser]danmontgomery[/eluser]
http://ellislab.com/codeigniter/user-gui...ml#default

Quote:CodeIgniter can be told to load a default controller when a URI is not present, as will be the case when only your site root URL is requested.

localhost/foldername/test isn't looking for the test() method in the default controller, it's looking for the test controller.
#4

[eluser]Honscho[/eluser]
God, I am such a tool.

You are right of course. This is now working.

Code:
http://localhost/foldername/index.php/start/test

To make it work like this I would have to modify the htaccess file, right?

Code:
http://localhost/foldername/start/test

Since I never really had to do that I was wondering if anyone has a link to an article somewhere that would tutor me in the right direction Smile


Thanks!
#5

[eluser]danmontgomery[/eluser]
I think what you probably want is to set up routing.




Theme © iAndrew 2016 - Forum software by © MyBB