G
G
glebvvs2018-12-09 12:41:54
Zend Framework
glebvvs, 2018-12-09 12:41:54

Why getters and setters in zf3?

Everyone will accept. I just can't understand the meaning of getters and setters in zend entities. Specifically, this is the question.
In fact, the Zend\Db doc offers us something like this option for updating the content in the tuples of the database, which is shown in the code below. And despite the fact that in my Album entity the properties have the protected access modifier, as a result, I can still use the $albumRow->artist = 'New Name'; and besides, in this context, I can't use $albumRow->setArtist('New Name'); instead. .

$adapter = new Adapter($this->config['db']);
        $resultSetPrototype = new ResultSet();
        $resultSetPrototype->setArrayObjectPrototype(new Album());
        $table = new TableGateway('album', $adapter, new RowGatewayFeature('id'), $resultSetPrototype);

        $results = $table->select(array('id' => 2));
        $albumRow = $results->current();
        $albumRow->artist = 'New Name';
        $albumRow->save();

Naturally, I am aware of my own inexperience, but if I'm doing something wrong, then someone can explain to me how to update, add tuples to the database using standard zend tools, while still being guided not by the style ala asset record , but humanly with accessors and mutators.
I would like to see how you can do something like this:
...
        $albumRow->setArtist('New Name');
        $albumRow->setTitle('New Title');
        $albumRow->save();

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Decadal, 2018-12-09
@Decadal

It's actually a thirst for Doctrine. Use it. What zend offers by default is not very good. Even in the most popular Russian-language doc zf3, a separate section
is devoted to this, but here is what one of the contributors of the doctrine and zend-db says

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question