CodeIgniter Forums

Full Version: Direct access to views
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[eluser]luukskywalker[/eluser]
I have a small question regarding views.

I am working on a login system for a new web application.
When users log in and validated their username and password, the variable logged_in in the session changes to true.

My question is:
Is it possible to access views via url's?

If not, then i can just check the loggin boolean at the beginning of the functions after users logged in.

El Forum

[eluser]Glen Swinfield[/eluser]
You cannot map an URL to a view, just make a controller method that includes your view and nothing else.

class Test extends Controller
{
function my_view(){
$this->load->view('my_view');
}
}

El Forum

[eluser]luukskywalker[/eluser]
Allright

Thanks

I was afraid people could get to my view by putting

http://www.website.com/codeigniter/my_view.php

in the address bar!

but its solved thanSmile

El Forum

[eluser]xwero[/eluser]
This is possible if you allow the view file as a stand alone file which is the case on most servers but you could set server restrictions in the .htaccess or the webserver configuration or you can add following line to the beginning of each view file
Code:
if (!defined('BASEPATH')) exit('No direct script access allowed');

El Forum

[eluser]MadZad[/eluser]
Additionally, it's generally wise to keep all files out of the webroot unless necessary. CI makes this very easy, and the only things I have left in the webroot are css/js/image files, an index.php and .htaccess for each application, and ci_config.php and .htaccess in my CI directory (above the application dirs).