Welcome Guest, Not a member yet? Register   Sign In
how to solve error message : Unable to load the requested file: main_content.php
#1

[eluser]ded0t[/eluser]
hi all,
i try to make a login form using CI 2.0 and i got this error message : Unable to load the requested file: main_content.php

even, there's a similar question in this thread "http://ellislab.com/forums/viewthread/155359/#751532", i still not understand how to solve that's error.

Controller side :

login.php
Code:
<?php

class Login extends CI_Controller
{

      function index()
    {
          $data['main_content'] = 'login_form';
          $this->load->view('includes/template', $data);
    }
}

?>

View side :

login_form.php
Code:
<div id="login_form">
<h1>Login Form</h1>

&lt;?php

  echo form_open('login/validate_credentials');
  echo form_input('username', 'Username');
  echo form_password('password', 'Password');
  echo form_submit('submit', 'Login');
  echo anchor('login/signup', 'Create Account');

  ?&gt;
</div>

template.php
Code:
&lt;?php $this->load->view('includes/header'); ?&gt;

&lt;?php $this->load->view('main_content'); ?&gt;

&lt;?php $this->load->view('includes/footer'); ?&gt;

header.php
Code:
&lt;html lang="en"&gt;
    &lt;head&gt;
        &lt;meta http-equiv="Content-Type" content="text/html; charset-utf-8"&gt;
        &lt;title&gt;
            login
        &lt;/title&gt;
    &lt;/head&gt;

    &lt;body&gt;

footer.php
Code:
&lt;/body&gt;

&lt;/html&gt;


Configuration :
routes.php
Code:
$route['default_controller'] = "login";

config.php
Code:
$config['base_url']    = 'http://localhost/Code2.0/';

autoload.php
Code:
$autoload['helper'] = array('url','form');


do i missing something? thanks in advance Smile
#2

[eluser]InsiteFX[/eluser]
Code:
class Login extends CI_Controller {

    function index()
    {
        $data['main_content'] = 'login_form';

        // makes all $data access to all views!
        $this->load->vars->($data);

        $this->load->view('includes/template');
    }
}

InsiteFX
#3

[eluser]ded0t[/eluser]
still not working Sad

after added a code "$this->load->vars->($data);",

i got error message "Parse error: syntax error, unexpected '(', expecting T_STRING or T_VARIABLE or '{' or '$' in C:\xampp\htdocs\Code2.0\application\controllers\login.php on line 11"

any solution? thanks Smile
#4

[eluser]InsiteFX[/eluser]
Try changing this:
Code:
&lt;?php $this->load->view($main_content);?&gt;

InsiteFX
#5

[eluser]ded0t[/eluser]
thanks mr.insiteFX..now it's works! Smile

even there's a little mistake in your code

i added
Code:
$this->load->vars($data);

not
Code:
$this->load->vars->($data);

and then, change
Code:
&lt;?php $this->load->view('main_content');?&gt;

on template.php with this code

Code:
&lt;?php $this->load->view($main_content);?&gt;
#6

[eluser]InsiteFX[/eluser]
Ya, sorry about that!

You can find out about $this->load->vars() in the CodeIgniter User Guide - Loader Class along with a few other ones.

InsiteFX




Theme © iAndrew 2016 - Forum software by © MyBB