Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

Phalcon\Mvc\Model getAttributes [solved]

Hi!!!

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



4.1k
Accepted
answer
edited Mar '14

Use Phalcon\Mvc\Model\MetaData (http://docs.phalconphp.com/en/latest/api/Phalcon%5Mvc%5Model%5MetaData.html):

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


23.2k

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();


23.2k

(y) Thanks!