CodeIgniter Forums

Full Version: Unable To call function from URL
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[eluser]Blue Sapphire[/eluser]
Hi!
I have following class code :

Code:
<?php

class Main extends Controller {

    function Main()
    {
        parent::Controller();
    }
/****************************************************/    
    function index()
    {
        echo 'index Function';
        //$this->load->view('admin/adwc');
    }
/***************************************************/    
    function myFunc()
    {
        echo 'Another Function';
    }
/**************************************************/    
    
}

?>


I have set route in routes.php as follows:
Code:
$route['admin'] = "admin/main";

I am using following url:

1- http://localhost/personal/com/admin/ [This works fine and shows message]

2- http://localhost/personal/com/admin/myFunc [This url gives me '404 Page Not Found' error].

Can some one guide me where I am wrong and in solving this problem.

Thanks in advance

El Forum

[eluser]Blue Sapphire[/eluser]
Any solution?

El Forum

[eluser]KPowell[/eluser]
When you set your routes, the first parameter is the controller, the second the method. So, in your example, you're trying to call the "main" method of the "admin" controller, which doesn't add up to what you have. If your application is admin, then setting the route to just "main" should do what you need.

El Forum

[eluser]Blue Sapphire[/eluser]
Thanks for guidance. I have following scenario:

1- 'admin' is sub directory of 'controllers' directory. 'admin' directory will hold all admin related controllers.

2- 'main' is default controller in 'admin' sub directory. There will be many more controllers in 'admin' sub directory.

3- 'myFunc' is function in 'main' controller.

Your guidance will be higly appreciated in this scenario.

Thanks in advance

El Forum

[eluser]Blue Sapphire[/eluser]
Any solution ?

Thanks in advance

El Forum

[eluser]yusufdestina[/eluser]
try http://localhost/personal/com/admin/main/myFunc