Friday, September 28, 2012

Re: SQL Error: 1064: You have an error in your SQL syntax;

I have commented this line and error disappear..  
/*
        $is_friend = in_array($this->user['id'], $this->Friend->myFriends($user['User']['id']));
      else
        $is_friend = false;
      */ 

can anyone tell me proper way to write this...? I think I need it to read code from model. 
 thanks 

On Friday, September 28, 2012 8:55:52 PM UTC-7, Chris wrote:
I have a function which works on 1.2 pre-Beta version,... but not working on 1.3 CAKE 
can anyone tells me whats wrong with this,... or what am I doing wrong,... THANKS 

SQL Error: 1064: You have an error in your SQL syntax;

      if($this->is_user())

        $is_friend = in_array($this->user['id'], $this->Friend->myFriends($user['User']['id']));
      else
        $is_friend = false;
      
      if($user['User']['privacy'] == array_search('friend', Configure::read('Site.privacy')))
      {
        if($this->user['id'] != $user['User']['id'] && !$is_friend)
        {
          $this->flash('error', ucfirst('this profile is only viewable by owner\'s friends'));
          $this->redirect('/send_request/' . $user['User']['username']);
        }
      }
      elseif($user['User']['privacy'] == array_search('private', Configure::read('Site.privacy')))
      {
        if($this->user['id'] != $user['User']['id'])
        {
          $this->flash('error', ucfirst('this profile is only viewable by its owner'));
          $this->redirect('/owner/' . $user['User']['username']);
        }
      }
      
      $this->set_title(ucfirst(i18n::translate('info')) . ' : ' . $user['User']['firstname'] . ' ' . $user['User']['lastname']);
      
      $this->set('user_obj', $user);
      

and this is my Friend model: 

<?php
class Friend extends AppModel {
  var $name = 'Friend';

    var $validate = array(
     'user_id' => array(
      'rule' => 'notEmpty',
      'message' => 'Please enter a valid user',
     ),
     'friend_id' => array(
      'rule' => 'notEmpty',
      'message' => 'Please enter a valid friend',
     ),
 );
 

  var $belongsTo = array('User' => array('foreignKey' => 'friend_id'));


  function myFriends($id = null)
  {
    $friends_ids = $this->generateList(array('Friend.user_id' => $id), array('Friend.friend_id' => 'ASC'), null, '{n}.Friend.friend_id', '{n}.Friend.friend_id');
    return is_array($friends_ids) ? $friends_ids : array();
  }


  function afterDelete()
  {
  }
}
?>

--
Like Us on FacekBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP
 
---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com.
To unsubscribe from this group, send email to cake-php+unsubscribe@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php?hl=en.
 
 

No comments: