D
D
dev4002016-09-11 00:22:29
PHP
dev400, 2016-09-11 00:22:29

Setter in constructor?

Whether the design is adequate:
A piece of code from the news model is shown, the base model comes to the constructor. The base model, like the news model, implements the ModelInterface.

public function __construct(ModelInterface $model) {

        $this->setTable('news');
        $this->model = $model;

    }

    private function setTable($table) {

        $this->table = BaseModel::PREFIX . $table;

    }

I set the working table in the constructor, and then use it in queries

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
shagguboy, 2016-09-11
@dev400

it is not necessary to hardcode the name of the table like this in the code. you can either make it into constants or make the name stupidly the name (part of the name) of the model class.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question