www.webdeveloper.com
Results 1 to 8 of 8

Thread: Simple error that I can't find

Hybrid View

  1. #1
    Join Date
    Dec 2012
    Posts
    7

    Simple error that I can't find

    This is the code that I'm working with right now. I'm missing a bracket somewhere but I'm not really well versed in PHP. Can you help me find it? I've currently got a parse error in line 133 if that helps but I suspect the error is before that point.

    <?php
    class ControllerAccountLogin extends Controller {
    private $error = array();

    public function index() {
    if ($this->customer->isLogged()) {
    $this->redirect(HTTPS_SERVER . 'index.php?route=account/account');
    }

    $this->language->load('account/login');

    $this->document->title = $this->language->get('heading_title');

    if (($this->request->server['REQUEST_METHOD'] == 'POST')) {
    if (isset($this->request->post['account'])) {
    $this->session->data['account'] = $this->request->post['account'];

    if ($this->request->post['account'] == 'register') {
    $this->redirect(HTTPS_SERVER . 'index.php?route=account/create');
    }

    if ($this->request->post['account'] == 'guest') {
    $this->redirect(HTTPS_SERVER . 'index.php?route=checkout/singlepage');
    }
    }

    if (isset($this->request->post['email']) && isset($this->request->post['password']) && $this->validate()) {
    unset($this->session->data['guest']);

    $this->load->model('account/address');

    $address = $this->model_account_address->getAddress($this->customer->getAddressId());

    $this->tax->setZone($address['country_id'], $address['zone_id']);

    if (isset($this->request->post['redirect'])) {
    $this->redirect(str_replace('&amp;', '&', $this->request->post['redirect']));
    } else {
    $this->redirect(HTTPS_SERVER . 'index.php?route=account/account');
    }
    }

    $this->document->breadcrumbs = array();

    $this->document->breadcrumbs[] = array(
    'href' => HTTP_SERVER . 'index.php?route=common/home',
    'text' => $this->language->get('text_home'),
    'separator' => FALSE
    );

    $this->document->breadcrumbs[] = array(
    'href' => HTTP_SERVER . 'index.php?route=account/account',
    'text' => $this->language->get('text_account'),
    'separator' => $this->language->get('text_separator')
    );

    $this->document->breadcrumbs[] = array(
    'href' => HTTP_SERVER . 'index.php?route=account/login',
    'text' => $this->language->get('text_login'),
    'separator' => $this->language->get('text_separator')
    );

    $this->data['heading_title'] = $this->language->get('heading_title');

    $this->data['text_new_customer'] = $this->language->get('text_new_customer');
    $this->data['text_i_am_new_customer'] = $this->language->get('text_i_am_new_customer');
    $this->data['text_checkout'] = $this->language->get('text_checkout');
    $this->data['text_register'] = $this->language->get('text_register');
    $this->data['text_guest'] = $this->language->get('text_guest');
    $this->data['text_create_account'] = $this->language->get('text_create_account');
    $this->data['text_returning_customer'] = $this->language->get('text_returning_customer');
    $this->data['text_i_am_returning_customer'] = $this->language->get('text_i_am_returning_customer');
    $this->data['text_forgotten_password'] = $this->language->get('text_forgotten_password');

    $this->data['entry_email'] = $this->language->get('entry_email_address');
    $this->data['entry_password'] = $this->language->get('entry_password');

    $this->data['button_continue'] = $this->language->get('button_continue');
    $this->data['button_guest'] = $this->language->get('button_guest');
    $this->data['button_login'] = $this->language->get('button_login');

    if (isset($this->error['message'])) {
    $this->data['error'] = $this->error['message'];
    } else {
    $this->data['error'] = '';
    }

    $this->data['action'] = HTTPS_SERVER . 'index.php?route=account/login';

    if (isset($this->request->post['redirect'])) {
    $this->data['redirect'] = $this->request->post['redirect'];
    } elseif (isset($this->session->data['redirect'])) {
    $this->data['redirect'] = $this->session->data['redirect'];

    unset($this->session->data['redirect']);
    } else {
    $this->data['redirect'] = '';
    }

    if (isset($this->session->data['success'])) {
    $this->data['success'] = $this->session->data['success'];

    unset($this->session->data['success']);
    } else {
    $this->data['success'] = '';
    }

    if (isset($this->session->data['account'])) {
    $this->data['account'] = $this->session->data['account'];
    } else {
    $this->data['account'] = 'register';
    }

    $this->data['forgotten'] = HTTPS_SERVER . 'index.php?route=account/forgotten';
    $this->data['guest_checkout'] = ($this->config->get('config_guest_checkout') && $this->cart->hasProducts() && !$this->cart->hasDownload());

    if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/account/login.tpl')) {
    $this->template = $this->config->get('config_template') . '/template/account/login.tpl';
    } else {
    $this->template = 'default/template/account/login.tpl';
    }

    $this->children = array(
    'common/column_right',
    'common/footer',
    'common/column_left',
    'common/header'
    );

    $this->response->setOutput($this->render(TRUE), $this->config->get('config_compression'));
    }

    private function validate(){
    if (!$this->customer->login($this->request->post['email'], $this->request->post['password'])) {
    $this->error['message'] = $this->language->get('error_login');
    }

    if (!$this->error) {
    return TRUE;
    } else {
    return FALSE;
    }
    }
    }
    ?>

  2. #2
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,333
    If you use this forum's [php]...[/php] tags around your code, it will be much easier to read (I'm assuming you actually indent your code? ).

    Anyway, you need one more "}" in your index() method to balance things out. It may just go at the end (as I tried, below, after manually indenting it), but double-check the logic to make sure that's right:

    PHP Code:
    <?php
    class ControllerAccountLogin extends Controller {

        private 
    $error = array();

        public function 
    index() {
            if (
    $this->customer->isLogged()) {
                
    $this->redirect(HTTPS_SERVER 'index.php?route=account/account');
            }
            
    $this->language->load('account/login');
            
    $this->document->title $this->language->get('heading_title');
            if ((
    $this->request->server['REQUEST_METHOD'] == 'POST')) {
                if (isset(
    $this->request->post['account'])) {
                    
    $this->session->data['account'] = $this->request->post['account'];
                    if (
    $this->request->post['account'] == 'register') {
                        
    $this->redirect(HTTPS_SERVER 'index.php?route=account/create');
                    }
                    if (
    $this->request->post['account'] == 'guest') {
                        
    $this->redirect(HTTPS_SERVER 'index.php?route=checkout/singlepage');
                    }
                }
                if (isset(
    $this->request->post['email']) && isset($this->request->post['password']) && $this->validate()) {
                    unset(
    $this->session->data['guest']);
                    
    $this->load->model('account/address');
                    
    $address $this->model_account_address->getAddress($this->customer->getAddressId());
                    
    $this->tax->setZone($address['country_id'], $address['zone_id']);
                    if (isset(
    $this->request->post['redirect'])) {
                        
    $this->redirect(str_replace('&amp;''&'$this->request->post['redirect']));
                    } else {
                        
    $this->redirect(HTTPS_SERVER 'index.php?route=account/account');
                    }
                }
                
    $this->document->breadcrumbs = array();
                
    $this->document->breadcrumbs[] = array(
                    
    'href' => HTTP_SERVER 'index.php?route=common/home',
                    
    'text' => $this->language->get('text_home'),
                    
    'separator' => FALSE
                
    );
                
    $this->document->breadcrumbs[] = array(
                    
    'href' => HTTP_SERVER 'index.php?route=account/account',
                    
    'text' => $this->language->get('text_account'),
                    
    'separator' => $this->language->get('text_separator')
                );
                
    $this->document->breadcrumbs[] = array(
                    
    'href' => HTTP_SERVER 'index.php?route=account/login',
                    
    'text' => $this->language->get('text_login'),
                    
    'separator' => $this->language->get('text_separator')
                );
                
    $this->data['heading_title'] = $this->language->get('heading_title');
                
    $this->data['text_new_customer'] = $this->language->get('text_new_customer');
                
    $this->data['text_i_am_new_customer'] = $this->language->get('text_i_am_new_customer');
                
    $this->data['text_checkout'] = $this->language->get('text_checkout');
                
    $this->data['text_register'] = $this->language->get('text_register');
                
    $this->data['text_guest'] = $this->language->get('text_guest');
                
    $this->data['text_create_account'] = $this->language->get('text_create_account');
                
    $this->data['text_returning_customer'] = $this->language->get('text_returning_customer');
                
    $this->data['text_i_am_returning_customer'] = $this->language->get('text_i_am_returning_customer');
                
    $this->data['text_forgotten_password'] = $this->language->get('text_forgotten_password');
                
    $this->data['entry_email'] = $this->language->get('entry_email_address');
                
    $this->data['entry_password'] = $this->language->get('entry_password');
                
    $this->data['button_continue'] = $this->language->get('button_continue');
                
    $this->data['button_guest'] = $this->language->get('button_guest');
                
    $this->data['button_login'] = $this->language->get('button_login');
                if (isset(
    $this->error['message'])) {
                    
    $this->data['error'] = $this->error['message'];
                } else {
                    
    $this->data['error'] = '';
                }
                
    $this->data['action'] = HTTPS_SERVER 'index.php?route=account/login';
                if (isset(
    $this->request->post['redirect'])) {
                    
    $this->data['redirect'] = $this->request->post['redirect'];
                } elseif (isset(
    $this->session->data['redirect'])) {
                    
    $this->data['redirect'] = $this->session->data['redirect'];
                    unset(
    $this->session->data['redirect']);
                } else {
                    
    $this->data['redirect'] = '';
                }
                if (isset(
    $this->session->data['success'])) {
                    
    $this->data['success'] = $this->session->data['success'];
                    unset(
    $this->session->data['success']);
                } else {
                    
    $this->data['success'] = '';
                }
                if (isset(
    $this->session->data['account'])) {
                    
    $this->data['account'] = $this->session->data['account'];
                } else {
                    
    $this->data['account'] = 'register';
                }
                
    $this->data['forgotten'] = HTTPS_SERVER 'index.php?route=account/forgotten';
                
    $this->data['guest_checkout'] = ($this->config->get('config_guest_checkout') && $this->cart->hasProducts() && !$this->cart->hasDownload());
                if (
    file_exists(DIR_TEMPLATE $this->config->get('config_template') . '/template/account/login.tpl')) {
                    
    $this->template $this->config->get('config_template') . '/template/account/login.tpl';
                } else {
                    
    $this->template 'default/template/account/login.tpl';
                }
                
    $this->children = array(
                    
    'common/column_right',
                    
    'common/footer',
                    
    'common/column_left',
                    
    'common/header'
                
    );
                
    $this->response->setOutput($this->render(TRUE), $this->config->get('config_compression'));
            }
        } 
    // added this <<-----------------<<<<<<<<<<

        
    private function validate(){
            if (!
    $this->customer->login($this->request->post['email'], $this->request->post['password'])) {
                
    $this->error['message'] = $this->language->get('error_login');
            }
            if (!
    $this->error) {
                return 
    TRUE;
            } else {
                return 
    FALSE;
            }
        }
    }
    ?>
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  3. #3
    Join Date
    Dec 2012
    Posts
    7
    Well thank god that parse error is now gone. Thanks so much!! Too bad I now have a fatal error that I have no idea of what its saying :-(
    Fatal error: Cannot access private property Document::$title in /home6/vickysdi/public_html/catalog/controller/account/login.php on line 11
    Like I said before... I'm not really familiar with php. I get that this has something to do with public and private classes or whatever but thats about where my understanding ends. Can you walk me through this one or if you know whats wrong, correct it? Thanks again for your help!

    And yes I do indent :-)

  4. #4
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,333
    If you are trying to access the validate() method from outside of that class, it won't be accessible (thus the "private" delcaraton ), e.g.:
    PHP Code:
    // this won't work:
    $foo = new ControllerAccountLogin();
    $result $foo->validate(); // run-time error

    // this would doubly not work, since it's private and not static:
    $result == ControllerAccountLogin::validate(); 
    However, since the controller's index method is already using validate() itself, one might wonder why anything external to that class would need to call it -- maybe you just need a public "getter" method to grab the $error class variable and check it?
    PHP Code:
        public function getError()
        {
            return 
    $this->error;
        } 
    If, on the other hand, it makes sense for the validate() method to be directly accessible, just change its declaration to public -- but keep in mind the OOP concept of encapsulation, making class properties and methods available outside of the class only when necessary (and logical).
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  5. #5
    Join Date
    Dec 2012
    Posts
    7
    Um... Wow. You spoke complete greek to me ... Soooo... Maybe you overestimated my knowledge in php lol... I have no idea of what you were trying to tell me... sorry!! Any chance you can simply tell me replace this bit of code with this? And from now on I promise not to mess with any more code because apparently I suck at it

  6. #6
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,333
    Well, at least part of your confusion is due to me seeing things in your second post that weren't there, so it may not be as bad as you think. (I'm not sure where I got the idea that the error message said anything about that validate() method, other than I suppose it was in my mind after looking at the first post.)

    The error appears to be about this line:
    PHP Code:
            $this->document->title $this->language->get('heading_title'); 
    Without knowing anything about your "document" object, nor now it gets into the class in question in the first place, it would be hard to know for sure what's going on. However, the gist of the problem would still seem to be the same, your code is trying to access the private property $title from the Document object $document -- and that's what "private" means in this context: it cannot be accessed except by methods of that Document class (and you are trying to access via a method in a different class, your ControllerAccountLogin class). So, you need to look at that class and see if there is, perhaps, a public "setter" method or such that allows you to set the document title from code external to the $document object/class.
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  7. #7
    Join Date
    Dec 2012
    Posts
    7
    There has to be an easier way... I really didn't change that much! Ugh... I have no idea of when to do or where to even go to look at the document class. All I know is that this particular php code its one of the codes for the login page for customers wanting to login to their account. I honestly doubt that helps you at all but I don't know what else to do . Do you know of anyone who can simply look at my file manager for my website and fix what I messed up? I know you are trying to help and I really appreciate it..

  8. #8
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,333
    The quick and dirty "fix" would be to find the Document class's file. I'm guessing it might be /home6/vickysdi/public_html/catalog/document.php, but that's just a guess based on where your login class was. If you find it, and somewhere in the Document class definition you find either of these:
    PHP Code:
    private $title;
    // or
    protected $title
    ...just change "private" or "protected" to "public".

    But this could be a real kludge if directly changing the title might have some unwanted side-effects.
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles