Answer the question
In order to leave comments, you need to log in
Answer the question
In order to leave comments, you need to log in
It is better, of course, to do it right away to the correct address, but you can just do a proxy_pass to the desired address, although this is not quite a replacement ...
Another option is to replace the status with 308 ...
1) https://ru.wikipedia.org/wiki/Model-View-Controller
2) It seems to me that it would be more useful for you to look at some normal framework like Yii2.
WordPress is just classic shit code.
Read about patterns. The book "Clean Code" helped me a lot ( www.ozon.ru/context/detail/id/21916535/).
Do not complicate your program, if it can be made easier - do it.
Don't write too much. If it is not required now, then it is not worth writing.
In your case, I see the following structure:
There is a connection pool class (eg ConnectionPool ). At the input it takes a string - the name of the repository, at the output it gives the connection to the database.
We break the program into entities: User , News , Page .
Each entity has its own storage: UserStorage , NewsStorage , PageStorage. The repository is only concerned with managing the entity in the database: save , load , delete , etc.
When created, the repository takes a connection to the database and saves it "in itself".
The code will look something like this:
$Connection = ConnectionPool::getConnection('users');
$UsersStorage = new UserStorage($Connection);
$User = $UsersStorage->loadById(1);
$User->set('name', 'Yakob');
$User->get('name');
$UserStorage->save($User);
$UserStorage->delete($User);
class UserFacade {
protected static $UserStorage = null;
public static function getById($id) {
return self::getUserStorage()->getById($id);
}
public static function save(User $User) {
return self::getUserStorage()->save($User);
}
protected static function getUserStorage() {
if (is_null(self::$UserStorage)) {
$Connection = ConnectionPool::getConnection('users');
self::$UserStorage = new UserStorage($Connection);
}
return self::$UserStorage;
}
}
....
$User = $UserStorage->getById(1);
$UsersNewsStorage = new UsersNewsStorage($Connection);
$Feeds = $UsersNewsStorage->getFeed($User);
$User = $UsersStorage->loadById(1);
$News = new News(['title'=>'AAA', 'body'=>'bbbbbb']);
$UsersNewsStorage = new UsersNewsStorage($Connection);
try {
$UsersNewsStorage->saveNews($User, $News); // Внутри валидация
} catch (ValidationNewsErrorException $Ex) {
// Валидация не прошла
}
As previously recommended, you need to understand and apply design patterns. A couple of books for review, which will definitely help www.ozon.ru/context/detail/id/5648968 and www.ozon.ru/context/detail/id/2457392/.
Also install and use some Yii or Laravel framework for example.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question