语法错误,意外'有' (T_STRING)

时间:2015-12-10 11:38:06

标签: newsletter php mage

如何解决此语法错误

  

意外'有' (T_STRING)in   /home/mithraa/public_html/svirtzone.com/projects/fandc/app/code/core/Mage/Newsletter/controllers/SubscriberController.php

public function unsubscribecusAction()
{
    $email = $this->getRequest()->getParam(’email’);
    $subsModel = Mage::getModel(’newsletter/subscriber’);
    $subscriber = $subsModel->loadByEmail($email);

    $id = (int) $subsModel->getId();
    $code = (string) $subsModel->getCode();
    if ($id && $code) {
        $session = Mage::getSingleton(’core/session’);
        try {
               Mage::getModel(’newsletter/subscriber’)->load($id)->setCheckCode($code)->unsubscribe();
               $session->addSuccess($this->__(’You have been unsubscribed.’));
        }
        catch (Mage_Core_Exception $e) {
            $session->addException($e, $e->getMessage());
        }
        catch (Exception $e) {
            $session->addException($e, $this->__(’There was a problem with the un-subscription.’));
        }
     }
     $this->_redirectReferer();
  } 

4 个答案:

答案 0 :(得分:1)

使用错误的引号字符来声明字符串:

<强>正确:

'hello', "hello"

<强>错误:

’hello’

答案 1 :(得分:0)

将(引号)更改为'

    public function unsubscribecusAction()
    {
      $email = $this->getRequest()->getParam('email');
      $subsModel = Mage::getModel('newsletter/subscriber');
      $subscriber = $subsModel->loadByEmail($email);

      $id = (int) $subsModel->getId();
      $code = (string) $subsModel->getCode();
        if ($id && $code) {
       $session = Mage::getSingleton('core/session');
        try {
        Mage::getModel('newsletter/subscriber')->load($id)->setCheckCode($code)->unsubscribe();
        $session->addSuccess($this->__('You have been unsubscribed.'));
        }
        catch (Mage_Core_Exception $e) {
              $session->addException($e, $e->getMessage());
        }
            catch (Exception $e) {
                 $session->addException($e, $this->__('There was a problem with the un-subscription.'));
            }
        }
        $this->_redirectReferer();
    }

答案 2 :(得分:0)

在您的代码中,您使用tiled sign符号代替在代码中的任何位置使用单'"。像是

’email’替换为'email'"email"

答案 3 :(得分:0)

我怀疑问题是'字符之间的区别。看看这是否有效;

public function unsubscribecusAction() {
    $email = $this->getRequest()->getParam('email');
    $subsModel = Mage::getModel('newsletter/subscriber');
    $subscriber = $subsModel->loadByEmail($email);

    $id = (int) $subsModel->getId();
    $code = (string) $subsModel->getCode();
    if ($id && $code) {
        $session = Mage::getSingleton('core/session');
        try {
            Mage::getModel('newsletter/subscriber')->load($id)->setCheckCode($code)->unsubscribe();
            $session->addSuccess($this->__('You have been unsubscribed.'));
        } catch (Mage_Core_Exception $e) {
            $session->addException($e, $e->getMessage());
        } catch (Exception $e) {
            $session->addException($e, $this->__('There was a problem with the un-subscription.'));
        }
    }
    $this->_redirectReferer();
}