Welcome Guest, Not a member yet? Register   Sign In
access to subFolder from subFolder
#1

[eluser]Mutsop[/eluser]
Hi,

I'm new to codeigniter and am quite excited to start my first application Big Grin

But as every rookie in this world, there are always "Brain hurters".

So.... As stated in this title:
I'm trying to access a view in a subfolder from a controller thats also set in a subfolder.

Example:
Controller: admin/login.php
View: admin/login.php

So in the controller I set
Code:
$this->load->view('admin/login', $data);

But I do get a 404 page.

When my controller is in the root of the controller folder it does work but not from a subfolder.

I also tried:
Code:
$this->load->view('../admin/login', $data);

But no use

Any help?

Kind regards
Muts (not real name :p)
#2

[eluser]danmontgomery[/eluser]
Views belong in application/views, not in the controllers folder...

Code:
/application
    /controllers
        /admin
            login.php
    /views
        /admin
            login.php

Then,
Code:
$this->load->view('admin/login', $data);
#3

[eluser]techgnome[/eluser]
The location of the view, is fine... how you are loading it (using "admin/login") is fine... what maybe causing the problem is how you are accessing your controller.... which should be : yoursitehere.com/admin/login the 404 isn't because of the view... the 404 happens because it can't find the controller... According to the User Guide, all you should need to do is include the subfolder name when calling the controller...

-tg
#4

[eluser]Mutsop[/eluser]
Well these are the two files I have:

application/controllers/admin/login.php
Code:
<?php

class Signup extends Controller {

    public function __construct() {
        parent::Controller();

        $this->load->helper(array('form','url'));
        $this->load->library('form_validation');
    }
    public function index() {
        $this->load->view('admin/login');
    }
    public function submit() {
        if ($this->_submit_validate() === FALSE) {
            $this->index();
            return;
        }
        // $this->load->view('submit_success');
    }
    private function _submit_validate() {
        // validation rules
        $this->form_validation->set_rules('username', 'Username', 'required');
        $this->form_validation->set_rules('password', 'Password', 'required');
        $this->form_validation->set_message('authenticate','Invalid login. Please try again.');
        return $this->form_validation->run();
    }
}
?>

application/views/admin/login.php
Code:
<!DOCTYPE html>
&lt;html lang="en"&gt;
&lt;head&gt;
    &lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8"&gt;
    &lt;title&gt;Admin Panel&lt;/title&gt;
    &lt;link rel="stylesheet" href="&lt;?php echo base_url(); ?&gt;css/style.css"
        type="text/css" media="all"&gt;
&lt;/head&gt;
&lt;body&gt;
    <div id="admin_login_form">
        &lt;?php echo validation_errors(); ?&gt;
        &lt;?php echo form_open('admin/login/submit'); ?&gt;
            <p>
                <label for="username">Username: </label>
                &lt;?php echo form_input('username'); ?&gt;
            </p>
            <p>
                <label for="password">Password: </label>
                &lt;?php echo form_password('password'); ?&gt;
            </p>
            <p>
                &lt;?php echo form_submit('submit','Login'); ?&gt;
            </p>
        &lt;?php echo form_close(); ?&gt;
    </div>
&lt;/body&gt;
&lt;/html&gt;

So the placement should be good...
#5

[eluser]Bart Mebane[/eluser]
Your controller filename has to match the class name.
#6

[eluser]Mutsop[/eluser]
Sigh...................

I should stop writing several pages at once Big Grin

Thanks alot




Theme © iAndrew 2016 - Forum software by © MyBB