Php – CodeIgniter loading a view through controller from another view

codeignitercontrollerPHP

For Security reasons as mentioned here http://codeigniter.com/user_guide/installation/index.html I have placed the system and application folders in another folder called OSW_appnsys, which is above the web root folder. Now I have a controller class called 'Pages' and a 'View' function in it in the following directory.

C:\wamp\www\OSW_appnsys\application\controllers

Now when I am calling the 'View' method of the controller 'Pages' from another view file called 'header.php' I am getting the 404 error like this

The requested URL /CodeIgniter_2.1.2/pages/view/products was not found on this server.

where product is the URI.

And I am calling this way:

<a class="mainmenu" href="<?php echo base_url('pages/view/products')?>">Products</a>

Any help will be highly appreciated. Ty

Best Answer

You don't link to a view, you link to the name of a controller. If your controller is named 'Pages', you have to link to:

<a class="mainmenu" href="<?php echo base_url('pages/controllers/products')?>">Products</a>

Assuming that you have placed your controllers in a 'pages/controllers/' folder. In the controller named 'pages' you load the view (a file named products_view.php or something, which is in your views folder) like so:

$this->load->view('products_view.php');
Related Topic