We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Phalcon\Mvc\Model getAttributes [solved]

Hi!!!

How can I get the attributes of the model within the model?



5.0k
Accepted
answer
edited Mar '14

Use Phalcon\Mvc\Model\MetaData (https://docs.phalcon.io/en/latest/api/Phalcon_Mvc_Model_MetaData.html):

$metaData = new Phalcon\Mvc\Model\MetaData\Memory();
$attributes = $metaData->getAttributes(new Robots());
print_r($attributes);


42.1k

I meant within the model

class TableA extends Model
{
    public function getAttributes() //Any method may be
    { //return attributes }}
}
class TableA extends Model{

.....

        /**
         * Get model attributes
         * 
         * @return array
         */
        public function getAttributes()
        {
            $metaData = $this->getModelsMetaData();
            return $metaData->getAttributes($this);
        }
}

$model = new TableA();
$attr = $model->getAttributes();


42.1k

(y) Thanks!