0
votes

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

3
and if I directly access the controller class through the complete directory link then I get the error "Forbidden. You dont have the permission to access application folder" - Saaram
if view is the method what is products the parameters to your method ? - Nishant Jani
products is the name of a view file products.php - Saaram
Did you do this step from documentation: After moving them, open your main index.php file and set the $system_folder and $application_folder variables, preferably with a full path, e.g. '/www/MyUser/system'. ? - tijs
we dont traditionally load views like this we would call the controller function pages/views and then $this->load->view('products'); - Nishant Jani

3 Answers

3
votes

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');
1
votes

It seems you may have understood how CodeIgniter works.

As above, within your configuration file, you will have

$application_folder = 'application';
$system_folder = 'system';

Change these to

$application_folder = '../OSW_appnsys/application';
$system_folder = '../OSW_appnsys/system';

Then point your browser to the URL of where the CodeIgniter's index.php exists.

i.e.

\
\OSW_appnsys
\OSW_appnsys\application
\OSW_appnsys\system
\htdocs
\htdocs\index.php

via

http://localhost/index.php

Also, when accessing controllers or views, you simply need to access the controller name. i.e.

<a href="<?php echo site_url('pages/view'); ?>">Go to page</a>

Then you would have a Page controller with a View action within which would do

<?php
class Pages extends CI_Controller {

    public function view()
    {
        echo $this->load->view('pages/view');
    }
}
?>
0
votes

try this in anchor tag

base_url().'index.php/pages/view'

and load view products.php in view function in Controller