CodeIgniter Forums
Form Post and Library Redeclare problem - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: Form Post and Library Redeclare problem (/thread-26804.html)



Form Post and Library Redeclare problem - El Forum - 01-23-2010

[eluser]monkeypaw201[/eluser]
I have a controller called MyAccount and a class called Account. MyAccount has a form which posts to itself and if validated updates the database. Unfortunately, I get an error and am unsure as to how it happened and how to fix it.

Error Message
Quote:Fatal error: Cannot redeclare class Account in /home/oitech/public_html/system/application/libraries/account.php on line 3

MyAccount Controller
Code:
<?php

class MyAccount extends Controller {

    function MyAccount()
    {
        parent::Controller();    
    }
    
    function index()
    {
        $this->load->library('data');
        $this->load->library('account');
        $this->load->library('form_validation');
        $this->load->helper(array('form', 'url'));
        
        $this->form_validation->set_rules('fname', 'First Name', 'required');
        $this->form_validation->set_rules('lname', 'Last Name', 'required');
        $this->form_validation->set_rules('email', 'Email Address', 'required');
        $this->form_validation->set_rules('address1', 'Address', 'required');
        $this->form_validation->set_rules('city', 'City', 'required');
        $this->form_validation->set_rules('state', 'State/Province', 'required');
        $this->form_validation->set_rules('zip', 'Zip Code', 'required');
        $this->form_validation->set_rules('phone', 'Phone Number', 'required');
        
        if ($this->form_validation->run() == FALSE)
        {
            $data = array(
                    'countrydropdown' => $this->data->countrydropdown($this->account->data('country')),
                    'fname' => $this->account->data('fname'),
                    'lname' => $this->account->data('lname'),
                    'company' => $this->account->data('company'),
                    'email' => $this->account->data('email'),
                    'address1' => $this->account->data('address1'),
                    'address2' => $this->account->data('address2'),
                    'city' => $this->account->data('city'),
                    'state' => $this->account->data('state'),
                    'zip' => $this->account->data('zip'),
                    'country' => $this->account->data('country'),
                    'phone' => $this->account->data('phone'),
                    );
            $this->parser->parse('account',$data);
        }else{
            $this->account->update('fname',$this->input->post('fname'));
            $this->account->update('lname',$this->input->post('lname'));
            $this->account->update('company',$this->input->post('company'));
            $this->account->update('email',$this->input->post('email'));
            $this->account->update('address1',$this->input->post('address1'));
            $this->account->update('address2',$this->input->post('address2'));
            $this->account->update('city',$this->input->post('city'));
            $this->account->update('state',$this->input->post('state'));
            $this->account->update('zip',$this->input->post('zip'));
            $this->account->update('country',$this->input->post('country'));
            $this->account->update('phone',$this->input->post('phone'));
        }
    }
}



Form Post and Library Redeclare problem - El Forum - 01-23-2010

[eluser]flaky[/eluser]
the error is on the account.php not myaccount.php so put the code of account.php in here


Form Post and Library Redeclare problem - El Forum - 01-23-2010

[eluser]monkeypaw201[/eluser]
Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Account {

    function login($username,$password)
    {
        $this->CI =& get_instance();
        
        $query = $this->CI->db->query("SELECT * FROM `clients` WHERE `username` = '".$username."' AND `password` = '".sha1($password)."'");
        if ($query->num_rows() > 0)
        {
            $row = $query->row();
            $this->CI->session->set_userdata('client_id', $row->client_id);
            return TRUE;
        }else{
            return FALSE;
        }
    }

    function logout()
    {
        $this->CI =& get_instance();
        $this->CI->session->unset_userdata('client_id');
    }

    function data($column='username')
    {
        $this->CI =& get_instance();
        $client_id = $this->CI->session->userdata('client_id');
        
        $query = $this->CI->db->query("SELECT * FROM `clients` WHERE `client_id` = '".$client_id."'");
        $row = $query->row_array();
        return $row[$column];
    }

    function notices()
    {
        $this->CI =& get_instance();
        $client_id = $this->CI->session->userdata('client_id');
        
        $query = $this->CI->db->query("SELECT * FROM `notices` WHERE `client_id` = '".$client_id."' AND `read` = '0'");
        $output = '<div class="pad20">';
        foreach ($query->result() as $row)
        {
            $output .= '<div class="message '.$row->type.' close" id="'.$row->notice_id.'">
                            <h2>'.$row->title.'!</h2>
                            <p>'.$row->message.'</p>
                        </div>';
        }
        $output .= '</div>';
        return $output;
    }
    
    function update($column,$value)
    {
        $this->CI =& get_instance();
        $client_id = $this->CI->session->userdata('client_id');
        
        $query = $this->CI->db->query("UPDATE `clients` SET `".$column."` = '".$value."' WHERE `client_id` = '".$client_id."' LIMIT 1");
    }

}

?&gt;



Form Post and Library Redeclare problem - El Forum - 01-23-2010

[eluser]JanDoToDo[/eluser]
It would appear there is already a class/library/method/function etc using the name "Account"


Form Post and Library Redeclare problem - El Forum - 01-23-2010

[eluser]monkeypaw201[/eluser]
Indeed, it is called in the Hook.. do I need to only load in there? I thought I had to re-call it in the controller?