Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

can't access the controller function(s) in code igniter

hi my folder sturcture is like this

controllers/user/registration/register.php

Inside the register.php controller there is let say for test index function saying 'hello world'.But i cant access the folder index through browser.

My base_url is

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

But while i write

localhost/new/index.php/user/registration/register/index

I got an error

The page you requested was not found. 

what is weird is, I can access the controller fxn of user folder but cant access the controller fxn inside registration folder .And for default controller i have 'home.php'

$route['default_controller'] = "home";
$route['404_override'] = '';

I just want to access the controller/user/registration/register/index fxn which says 'hello world' but it says an error-'The page you requested was not found'. Thanks

like image 457
ugene Avatar asked Dec 18 '12 08:12

ugene


People also ask

How to access controller in CodeIgniter?

CodeIgniter permits you to do this. Simply create sub-directories under the main application/controllers/ one and place your controller classes within them. Each of your sub-directories may contain a default controller which will be called if the URL contains only the sub-directory.

How to call controller method in CodeIgniter?

By default Controller always calls index method. If you want a different method, then write it in the Controller's file and specify its name while calling the function. Look at the URL, there is no method name is mentioned.

What is ci_ controller in CodeIgniter?

The pages class is extending the CI_Controller class. This means that the new pages class can access the methods and variables defined in the CI_Controller class ( system/core/Controller. php ). The controller is what will become the center of every request to your web application.

How to add routes in CodeIgniter 4?

Routing rules are defined in your application/config/routes. php file. In it you'll see an array called $route that permits you to specify your own routing criteria. Routes can either be specified using wildcards or Regular Expressions.


2 Answers

Codeigniter only supports a single level directory structure for Controllers.

Try this link below for Multi Level Subfolder Controller in CodeIgniter :

Multi Level Subfolder Controller in CodeIgniter

like image 54
hsuk Avatar answered Oct 16 '22 14:10

hsuk


Ok after writing some hunch code in my test project ,finally it worked in my case So here it goes I follow this link Multi Level Subfolder Controller in CodeIgniter(thanks to K u s h)

http://glennpratama.wordpress.com/2009/10/20/multi-level-subfolder-for-controller-in-codeigniter/

and copy the code and paste in my new/application/core/MY_Router.php as told in that link and an error came to me like this

Call to undefined method CI_Router::CI_Router() in C:\xampp\htdocs\new\application\core\MY_Router.php

So i changed a little portion of that code to

//  Function MY_Router()
//  {
//      parent::CI_Router();
//  }
   public function __construct()
   {
        parent::__construct();
        // Your own constructor code
   }

And after i was able to access the controllers/user/registration/register.php index fxn

It worked in my case.Thanks to all

like image 41
ugene Avatar answered Oct 16 '22 14:10

ugene