UFO ET IT

WordPress MVC를 준수합니까?

ufoet 2020. 11. 24. 20:40
반응형

WordPress MVC를 준수합니까?


어떤 사람들은 WordPress를 블로깅 플랫폼이라고 생각하고 어떤 사람들은 CMS로 생각하고 어떤 사람들은 WordPress를 개발 프레임 워크라고합니다. 그것이 무엇이든, 질문은 여전히 ​​남아 있습니다. WordPress MVC를 준수합니까?

저는 포럼을 읽었고 누군가가 약 3 년 전에 MVC에 대해 질문했습니다. 긍정적 인 대답과 부정적인 대답이있었습니다. 아무도 MVC가 무엇인지 정확히 알지 못하며 모든 사람들이 자신의 방식으로 그것에 대해 생각하지만, 모든 토론에 여전히 존재하는 일반적인 개념이 있습니다.

나는 MVC 프레임 워크에 대한 경험이 거의없고 프레임 워크 자체에 대해서는 아무것도없는 것 같습니다. 대부분의 MVC는 프로그래머가 수행합니다. 맞습니까? 이제 WordPress로 돌아가서 핵심 재 작성 엔진 (WP_Rewrite)을 컨트롤러로 고려할 수 있습니까? 모델로 쿼리 및 플러그인 로직? 그리고 테마로보기? 아니면 내가 모든 것을 잘못 알고 있습니까?

감사 ;)


Wordpress 자체는 MVC로 설계되지 않았지만 프레임 워크 내에서 매우 MVC 지향적 인 테마와 플러그인을 구축 할 수 있습니다. 도움이 될 수있는 몇 가지 도구가 있습니다.

WordPress MVC 솔루션 :

WordPress.org Ideas 및 Trac의 MVC 스레드 :


Wordpress는 일종의 MVC입니다. 뷰가 모델에서 데이터를 '풀링'하는 풀 유형 MVC 레이아웃입니다. 많은 다른 객체를 사용하는 대신 매우 절차적인 방식으로이 작업을 수행하지만 실제로 프런트 엔드 템플릿을 여러 방법으로 작성하기가 더 쉽습니다.

이것은 또한 뷰에 어느 정도의 컨트롤러 로직을 제공합니다 (따라서 일종의 MVC).

이것을 실행하자 : Wordpress는 URL을 얻습니다. 워드 프레스 코어는 컨트롤러 역할을하며 데이터베이스에서 실행할 초기 쿼리를 결정하고 확장에 따라로드해야하는보기 (카테고리보기, 단일 게시물 또는 페이지보기 등)를 결정합니다. 그런 다음 해당 INTIAL 쿼리 응답을 패키징하여보기 파일로 보냅니다.

해당 뷰 파일은 엄격한 표시 전용 파일이거나 내장 된 파일 이외의 추가 정보 / 쿼리를 요청할 수 있습니다. 이것은 MVC의 풀 유형으로, 뷰는 컨트롤러가 모델에서 뷰로 데이터를 '푸시'하는 대신 모델에서 데이터를 가져옵니다.

따라서 뷰가 사이드 바 또는 위젯 영역을로드하는 코드를 볼 때 해당 정보를 요청합니다. 그러나 어떤 위젯이 있어야하는지는 컨트롤러에 의해 결정됩니다. 컨트롤러는 사이드 바에 어떤 위젯이 있는지 모델을 살펴본 다음 현재 페이지에 표시되도록 설정된 위젯을 선택하고 해당 위젯을보기로 반환합니다.

그 각 부분이 객체가 아니라고해서 MVC가 줄어들지는 않습니다. 테마에 대해 (필수적으로) 변경하지 않고 WP 코어를 변경할 수 있습니다. 마찬가지로 'get_pages ()'와 같은 내장 함수를 사용하는 한 해당 함수가 올바른 데이터를 반환하는 한 모델과 데이터베이스 테이블이 변경 될 수 있습니다. 따라서 모델은 뷰와 독립적이며 컨트롤러도 독립적입니다 (뷰가 컨트롤러 로직을 추가하여 코어가 일반적으로 수행하는 것보다 더 많은 작업을 수행하는 경우 제외).

WPModel :: get_pages ( 'blah blah')와 같은 많은 메소드와 물건을 보유하고있는 모델 객체를 가질 수 있고, 그런 식으로 모든 것을 포함 할 수 있지만, 여전히 근본적인 문제 분리가 있습니다.

보기 : 템플릿 파일 컨트롤러 : WP 코어 모델 : 특정 데이터 처리를 처리하는 다양한 기능.

이름, 주장 등이 동일하게 유지되는 한 (또는 새 항목 만 추가하면) 우려의 분리가 유지되고 다른 하나를 방해하지 않고 하나를 변경할 수 있습니다.

MVC의 매우 깨끗한 버전은 아니지만 (특히 후크가 관련 될 때) 기본 수준에서 시작됩니다.

그리고 그것에 대해 절차적인 것은 IMO가 나쁜 것이 아닙니다. 웹 사이트의 요청은 본질적으로 매우 절차 적입니다. 시작과 끝이 명확한 프로세스이며 요청을 처리하고 데이터를 가져오고 패키징 한 다음 죽는 절차 만 있으면됩니다. 객체와 객체 메소드 및 OOP 레이아웃 (일부 작업이 더 쉬워 짐)을 사용하여 이러한 단계를 설정하거나 함수 호출을 많이 작성하여 분리 할 수 ​​있습니다. 개인 변수와 같은 클래스 멤버는 그런 식으로 손실되지만 응용 프로그램의 필요에 따라 ... 신경 쓰지 않을 수 있습니다.

개발을위한 일방적 인 방법이 없으며 WP는 웹 사이트의 약 20 %에 위치하므로 올바른 일을하고 있습니다. 아마도 사람들이 복잡한 클래스 계층 구조를 배우거나 암기하여 데이터베이스가 '페이지 x의 하위 페이지는 무엇입니까?'라는 질문에 대답하도록 만들지 않는 것과 관련이있을 것입니다. 그 데이터를 처리합니다. OOP로 쉽게 만들 수 있습니까? 예,하지만 Joomla가 OOP를 사용하여 복잡한 사용자 지정 웹 사이트를 구현하는 것이 얼마나 어려운지 보여주는 예라면 WP는 훨씬 쉽고 빠르며 시간은 돈입니다.


의견에서 이미 언급했듯이 MVC는 특정 프레임 워크가 아닌 아키텍처 디자인 패턴이며, 아닙니다. Wordpress는 MVC 패턴을 따르지 않습니다.

프로그래밍 로직과 뷰 (템플릿)가 분리되어 있지만, 관리자 패널이 아닌 프런트 엔드에서만 가능하며 뷰와 애플리케이션 로직의 일반적인 분리는 필연적으로 MVC가 아닙니다. MVC 패턴의 구현은 일반적으로 그 뒤에 어떤 종류의 객체 지향 프로그래밍 패러다임을 가정하고 Wordpress는 주로 PHP 함수에서 일반 SQL 쿼리를 사용하여 절차 적 방식으로 구현되므로 실제 모델도 없습니다.


검색 엔진에서이 문제를 해결하는 사람들을 위해 최신 정보를 업데이트하기 위해 wp-mvc 플러그인 http://wordpress.org/extend/plugins/wp-mvc/ 는 플러그인 개발을위한 mvc 프레임 워크를 만드는 데 큰 도움이됩니다. 자세한 내용은 http://wpmvc.org/documentation/70/tutorial/ 에서 확인할 수 있습니다 .


WordPress와 관련하여 토론에서 주기적으로 발생하는 주제 중 하나는 WordPress 및 MVC의 아이디어입니다.

하지만 문제는 MVC가 웹 개발의 은색 총알이 아니라는 것입니다. 예, 이것은 멋진 디자인 패턴이며 개인적으로 장갑처럼 웹 애플리케이션 모델에 적합하다고 생각하지만 모든 프레임 워크 나 플랫폼이 해당 디자인 패턴을 구현하는 것은 아닙니다.

적절한 사례 : WordPress는 MVC가 아닙니다.

그리고 괜찮습니다. 특히 워드 프레스가 제공하는 패턴이 충분할뿐만 아니라 올바르게 활용 될 때 잘 작동하는 경우에는 프로젝트에 적용하려는 욕구를 제쳐 두어야한다고 생각합니다.

"하지만 MVC를 사랑합니다!"

나도 그래! 사실, 저는 작년에 MVC 아키텍처를 거의 모방 한 프로젝트에 보냈습니다. MVC의 높은 수준의 예입니다.

여기에 이미지 설명 입력

MVC의 높은 수준의 예입니다.

예를 들면 :

Views were implemented using templates
Controllers were implemented by a combination of using function names like create, read, update, destroy, delete, and so on (even though these functions were hooked into the WordPress API
Models were functions also were called to validate and verify data prior to serializing the data. Again, this required that certain functions be hooked into WordPress to achieve the desired result.

Finally, a set of rewrite rules gave the application a clean set of predictable URLs in the format of /people/update/1 or /people/all. What Pattern Does WordPress Implement?

WordPress implements the event-driven architecture (of which there are several variations such as the Observer Pattern).

In short, you can conceptually think of this as the following:

Things happen when WordPress is processing information.
You can register your own function to fire when these things happen.

Not too complicated, is it? A high-level example of event-driven patterns 여기에 이미지 설명 입력 A high-level example of event-driven patterns

When you begin to think in terms of the paradigm in which it works rather than trying to make it work the way that you want it to work, it’s liberating. It helps to solve problems much more easily.

The bottom line is this: WordPress implements the event-driven design pattern, so even if you end up trying to implement MVC, you’re still going to have to utilize the hook system.

If you’re not careful, you can end up trying to craft the perfect architecture without actually getting your work done, and thus end up finding yourself so high up in the atmosphere of software that you’ve effectively become an architecture astronaut. So You’re Saying Avoid Design Patterns?

Not at all! Design Patterns serve a purpose because, above all else, they basically give us solutions to previously and commonly solved problems. Use them!

But the point I’m trying to make is that we don’t need to try to force things to fit pattern just because we like the pattern. That’s not their purpose. Instead, leverage the primary pattern that your platform of choice implements – in our case, it’s an event-driven pattern – and then implement patterns where they fit (such as dependency injection or something like that).

Otherwise, it’s like trying to put your foot in a glove.

Courtesy (and totally copied :P) from : http://tommcfarlin.com/wordpress-and-mvc/


Just to add to the list of options, (I'm admittedly biased as the author,) swpMVC is a fully featured, lightweight MVC framework, inspired by Rails, Sinatra, Express, and FuelPHP. It's thoroughly documented, and while I have used and enjoyed wp-mvc, I wanted something where the models were able to populate views themselves, including form controls for interacting with said models.

I put this together largely to reduce the amount of controller code required to put together an app on top of WordPress, and the result is a very fast and effective framework that runs inside WordPress. The models are based on PHP Activerecord and 8 models are included for existing WordPress data types, including Post, PostMeta, User, UserMeta, Term, and a few more. Modeling data is very easy thanks to the activerecord library, and I've enjoyed working with this framework immensely thus far.

Also ships with underscore PHP and PHP Quick Profiler (as seen in FuelPHP.)


RokkoMVC is a micro MVC framework built especially for WordPress. The project is meant to simplify AJAX functionality in WordPress applications, as well as bringing in all the other benefits of using models, views, and controllers to your theme.


I had a bash recently at creating a plugin that makes use of a simple view-controller system, and quite liked the results, so I separated the template stuff out to its own repo. It offers object-based controllers, passing variables locally to PHP templates, template fragments (templates within templates) and components (template fragments with their own sub-controller). All in two tiny classes!

Of course, I wrote this code thinking that no other WP developer had considered the problem before ;-).


그것은 mvc와는 거리가 멀고, 어떤 사람들이 말하는 것과 같은 종류의 소르 타는 없습니다. MVC이든 아니든 ... 뷰 레벨에서 로직을 작성한다는 사실은 그것을 mvc 프레임 워크로 규정하지 않습니다. 사람들이 그것을 사용하는 이유-배우기 쉽고, 하드 코어 PHP 프로그래머가 될 필요가 없으며, 게으르다.

참고 URL : https://stackoverflow.com/questions/2857143/is-wordpress-mvc-compliant

반응형