Welcome Guest, Not a member yet? Register   Sign In
'Object Not Found' - Beginner Issue
#1

[eluser]Butters[/eluser]
Hi folks,
I'm new to CodeIgniter and after reading a few tutorials etc I have tried a simple log-in page. I've only got as far as trying to echo out the validation errors as its failing. When you submit the form I'm getting an 'Object Not Found' error at the url localhost/codeigniter/user/login
.
Here is my form:
Code:
<div>
&lt;? echo form_input(array('id' => 'username', 'name' => 'username')); ?&gt;
</div>
</li>
<li><label>Password</label>
<div>
&lt;? echo form_password(array('id' => 'password', 'name' => 'password')); ?&gt;
</div></li>
<li>&lt;?php echo form_submit(array('name' => 'submit'), 'Login'); ?&gt;</li>
<li>&lt;? echo validation_errors(); ?&gt;</li>
</ul>

&lt;?php echo form_close();  ?&gt;
</div>

The controller:
Code:
&lt;?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class User extends CI_Controller {

    public function index()
    {
    $this->login();
    }
    
    function login()
    {
            $this->form_validation->set_rules('username','Username','required|trim|max_length[50]|xss_clean');
            $this->form_validation->set_rules('password','Password','required|trim|max_length[100]|xss_clean');
            $this->load->view('view_login');
            
            if ($this->form_validation->run() == FALSE)
            {
            
            }
            else
            {
                echo 'Success';
            }
    }
}

In routes.php I've set the default controller to 'user'
In config.php I've tried setting the index page to index.php,user.php and an empty string.

Can anybody spot what I am doing wrong Sad? If i've left any info out that might be needed to solve the problem let me know.

Cheers in advance!
#2

[eluser]Nick_MyShuitings[/eluser]
Perhaps you've autoloaded it, but if not I don't see where you loaded the form_validation library.

Also, actually giving us the error really helps debugging.
#3

[eluser]Butters[/eluser]
[quote author="Nick_MyShuitings" date="1303871334"]Perhaps you've autoloaded it, but if not I don't see where you loaded the form_validation library.

Also, actually giving us the error really helps debugging.[/quote]
Yeah form validation is autoloaded: $autoload['libraries'] = array('form_validation');

The error is:
Quote:Object not found!

The requested URL was not found on this server. The link on the referring page seems to be wrong or outdated. Please inform the author of that page about the error.

If you think this is a server error, please contact the webmaster.

Error 404

localhost
Tue Apr 26 22:39:04 2011
Apache/2.2.14 (Unix) DAV/2 mod_ssl/2.2.14 OpenSSL/0.9.8l PHP/5.3.1 mod_perl/2.0.4 Perl/v5.10.1
The URL it is trying to hit is: http://localhost/codeigniter/user/login

Within the CodeIgniter folder > Applications > Views I have view_login.php and in the controllers folder I have users.php
#4

[eluser]Nick_MyShuitings[/eluser]
Is the controller users or user? because the class is user... so if you have the controller filename as users.php then that might be the issue.
#5

[eluser]Butters[/eluser]
Apologies, that was a typo in my last post. The file is user.php
#6

[eluser]InsiteFX[/eluser]
Your loading your view before it even gets to the form_validation!
Code:
function login()
    {
            $this->form_validation->set_rules('username','Username','required|trim|max_length[50]|xss_clean');
            $this->form_validation->set_rules('password','Password','required|trim|max_length[100]|xss_clean');
            
            if ($this->form_validation->run() == FALSE)
            {
                $this->load->view('view_login');
            }
            else
            {
                echo 'Success';
                $this->load->view('view_success');
            }
    }

InsiteFX
#7

[eluser]Butters[/eluser]
[quote author="InsiteFX" date="1303878088"]Your loading your view before it even gets to the form_validation!
Code:
function login()
    {
            $this->form_validation->set_rules('username','Username','required|trim|max_length[50]|xss_clean');
            $this->form_validation->set_rules('password','Password','required|trim|max_length[100]|xss_clean');
            
            if ($this->form_validation->run() == FALSE)
            {
                $this->load->view('view_login');
            }
            else
            {
                echo 'Success';
                $this->load->view('view_success');
            }
    }

InsiteFX[/quote]
Ah, so I am... I made the change however the same error is occurring, it seems as if the call to the form on the submit button isn't hitting the proper location.
Cheers for taking the time to look at this Smile
#8

[eluser]InsiteFX[/eluser]
I do not see your form_open!
Code:
<div>
    &lt;?php echo form_open('user/login');?&gt;
</div>
<div>
&lt;? echo form_input(array('id' => 'username', 'name' => 'username')); ?&gt;
</div>
</li>
<li><label>Password</label>
<div>
&lt;? echo form_password(array('id' => 'password', 'name' => 'password')); ?&gt;
</div></li>
<li>&lt;?php echo form_submit(array('name' => 'submit'), 'Login'); ?&gt;</li>
<li>&lt;? echo validation_errors(); ?&gt;</li>
</ul>

&lt;?php echo form_close();  ?&gt;
</div>

InsiteFX
#9

[eluser]Aken[/eluser]
You forgot to use the __construct() function in your controller, which calls the CI_Controller __construct() function.
Code:
&lt;?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class User extends CI_Controller {

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

    public function index()
    {
        $this->login();
    }
    
    function login()
    {
        // Your login controller code here.
    }
}
#10

[eluser]InsiteFX[/eluser]
You do not need the Constructor unless you are setting variables!

The constructor is inherited from the CI_Controller!
If you are doing something like this then yes you need the Constructor
otherwise you do not!
Code:
private $CI;

    public function __construct()
    {
        parent::__construct();
        
        $this->CI =& get_instance();
    }

Here is a good article on Constructors from Greg!

Constructor-structor, what's your function?

InsiteFX




Theme © iAndrew 2016 - Forum software by © MyBB