2

I am following a tutorial from a book named Magento cookbook. But even though I followed all the codes, I keep on getting this error.

Parse error: syntax error, unexpected 'constSTATUS_PENDING' (T_STRING), expecting function (T_FUNCTION) in C:\xampp\htdocs\magento\app\code\Packt\HelloWorld\Model\Subscription.php on line 7

namespace Packt\HelloWorld\Model;
class Subscription extends \Magento\Framework\Model\AbstractModel
{

    constSTATUS_PENDING = 'pending';
    constSTATUS_APPROVED = 'approved';
    constSTATUS_DECLINED = 'declined';

    public function __construct(
        \Magento\Framework\Model\Context $context,
        \Magento\Framework\Registry $registry,
        \Magento\Framework\Model\ResourceModel\AbstractResource $resource = null,
        \Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
        array $data = [])
    {

            parent::__construct($context,$registry, $resource, $resourceCollection, $data);
    }

    public function _construct()
    {
        $this->_init('Packt\HelloWorld\Model\ResourceModel\Subscription');
    }
}

3 Answers 3

1

You should add a space after "const":

const STATUS_PENDING = 'pending';
const STATUS_APPROVED = 'approved';
const STATUS_DECLINED = 'declined';
5
  • the error is now gone but i got another
    – nieru
    Dec 29, 2016 at 2:15
  • What error do you get now? Dec 29, 2016 at 2:16
  • Fatal error: Class Packt\HelloWorld\Model\ResourceModel\Subscription contains 1 abstract method and must therefore be declared abstract or implement the remaining methods (Magento\Framework\Model\ResourceModel\AbstractResource::_construct) in C:\xampp\htdocs\magento\app\code\Packt\HelloWorld\Model\ResourceModel\Subscription.php on line 12
    – nieru
    Dec 29, 2016 at 2:16
  • Can you post your current code cause it doesn't show an abstract function above. You should also make the function _construct() protected like in the class you are extending Dec 29, 2016 at 2:23
  • I posted it on answers
    – nieru
    Dec 29, 2016 at 2:26
0
<?php

namespace Packt\HelloWorld\Model;

class Subscription extends \Magento\Framework\Model\AbstractModel{


    const STATUS_PENDING = 'pending';
    const STATUS_APPROVED = 'approved';
    const STATUS_DECLINED = 'declined';

    public function __construct(

        \Magento\Framework\Model\Context $context,
        \Magento\Framework\Registry $registry,
        \Magento\Framework\Model\ResourceModel\AbstractResource $resource = null,
        \Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
        array $data = [])
    {
        parent::__construct($context,$registry, $resource, $resourceCollection, $data);
    }

    public function _construct()
    {
        $this->_init('Packt\HelloWorld\Model\ResourceModel\Subscription');
    }
}

this is my current code

1
0

The problem is not in your Model but in your ResoureModel class "Packt\HelloWorld\Model\ResourceModel\Subscription". You should implement 2 abstract methods from the "Magento\Framework\Model\ResourceModel\AbstractResource" class:

abstract protected function _construct();
abstract protected function getConnection();
1
  • I already figured out my error Thank you so much!
    – nieru
    Dec 29, 2016 at 2:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.