What's Router, Listener, Controller Public ?

Thảo luận trong 'Development Tutorials' bắt đầu bởi VXF, 4/2/13.

1votes
5/5, 1 vote

  1. VXF

    VXF Be like no other .. Staff Member

    Bài viết:
    1,277
    Likes :
    2,175
    XenForo uses a framework, some stuff is from Zend, the majority is their own. But compared to many frameworks for PHP it's kinda the same, kinda.

    mvc

    You will find add-ons with directories such as Route/ Listener/ Controller/ Model/ etc.

    Here's my quick and dirty explanation that helps you get started. And by all means, please do extend on it in the comments, I need to improve what I know (big time).

    Route
    Usually not used, unless you have to introduce a new route or manipulate one.
    For example, the VietXF "Popular Content" plugin uses a route, because it is a new .com/popular/ page.

    Listener
    Used when you have code event listeners, such as injecting your own template inside existing templates. Great for certain customizations where you want upgrades to new versions to be smooth, without touching the original templates.

    Model
    Used to communicate with the database, you get data in there, use it to query the database, and get data out of there. The VietXF "Advanced Forum Statistics" add-on for example uses this to get the right users from the database. So we know which accounts are newest, most like, highest post (that we want to display later).

    Views
    Or ViewPublic or Public, this seems to vary a bit with XenForo, but it's a helper for the templates. Basically once we're done with whatever we have, we parse it back on to the templates and get an output to the user. Maybe it's that English isn't my first language, but I find it a bit hard to explain this one properly.

    Controller
    This is basically the guy that takes the input, decides how to handle it and directs the rest of the system as to what to do next.

    Now that we have a beginners idea of what things are, in a very dirty and simple visual explanation you could view it like this.

    When someone goes to say /popular/ it has to be a route that exists. So we need a Route.
    Since we now want something, let's provide the Controller with some data. Which could call a Model if some data has to be queried. And pass it on to a public viewer that handles the template and gives it what it needs.

    So some plugins don't need a new Route, some don't need a model.
    Sometimes it's as simple as 'hook into this template, with our template' and creating a code event listener for this is enough.

    And basically if you need to think about creating a plugin you need to go through the thinking steps of 'is it a separate new page? does it need to query data from the database? do i need to create my custom templates? etc.' Which might help you get started prototyping your add-on. Slowly populating the files until you end up with a working alpha ready for testing.

    I am looking forward to you guys posting better explanations, perhaps I am simply seeing this incorrectly, please let me know.
     
    hieucocc thích bài này.
    Đang tải...
  2. VXF

    VXF Be like no other .. Staff Member

    Bài viết:
    1,277
    Likes :
    2,175
    Vietnamese Version
    XenForo sử dụng một loại framework, một số được lấy từ Zend, còn đa số là của riêng. Nhưng so với nhiều framework cho PHP thì đều gần giống nhau.

    [​IMG]

    Bạn sẽ tìm thấy add-ons với các thư mục như Route / Listener / Controller / Model / v.v

    Dưới đây là giải thích đơn giản của tôi giúp bạn có thể bắt đầu làm quen và xin hãy giúp tôi hoàn thiện hơn bằng cách cho ý kiến và góp ý của bạn.

    Route
    Thường thì không được sử dụng nhiều, trừ khi bạn giới thiệu một Route mới . Ví dụ, VietXF plugin sử dụng một Route (tuyến đường), bởi vì nó là .com/popular/ page.

    Listener
    Used when you have code event listeners, such as injecting your own template inside existing templates. Great for certain customizations where you want upgrades to new versions to be smooth, without touching the original templates.

    Model
    Được sử dụng để giao tiếp với cơ sở dữ liệu, bạn sẽ có được dữ liệu trong đó, sử dụng nó để truy vấn cơ sở dữ liệu, và có được dữ liệu ra khỏi đó. VietXF "Advanced Forum Statistics" sử dụng Model để mà thống kê được những thành viên mới, được thích nhiều nhất và post nhiều nhất.

    Views
    Or ViewPublic or Public, this seems to vary a bit with XenForo, but it's a helper for the templates. Basically once we're done with whatever we have, we parse it back on to the templates and get an output to the user. Maybe it's that English isn't my first language, but I find it a bit hard to explain this one properly.

    Controller (người điều khiển)
    Controller quyết định làm thế nào để xử lý và chỉ đạo phần còn lại của hệ thống phải làm gì tiếp theo.

    When someone goes to say /popular/ it has to be a route that exists. So we need a Route.
    Since we now want something, let's provide the Controller with some data. Which could call a Model if some data has to be queried. And pass it on to a public viewer that handles the template and gives it what it needs.

    So some plugins don't need a new Route, some don't need a model.
    Sometimes it's as simple as 'hook into this template, with our template' and creating a code event listener for this is enough.

    Về cơ bản nếu bạn cần phải suy nghĩ về việc tạo ra một plugin bạn cần phải đi qua các bước suy nghĩ của "một trang mới riêng biệt? không cần phải truy vấn dữ liệu từ cơ sở dữ liệu? làm tôi cần phải tạo ra các mẫu tùy chỉnh của tôi? vv 'Mà có thể giúp bạn bắt đầu tạo mẫu add-on của bạn. Slowly populating the files until you end up with a working alpha ready for testing.

    Tôi đang mong muốn có 1 ai đó viết 1 bài liên quan như thế này nhưng sẽ rõ ràng và nhiều thông tin hơn cái của tôi. Hãy cho tôi xin ý kiến từ bạn.

    Translated by Mr.iCoder: Sorry các bác vì dịch nguyên 1 bài dài mà toàn từ ngữ code cho nên ra tiếng việt sẽ rất là "chuôi" có nhiều đoạn em mong các bác đọc và hiểu nhé. Chứ dịch ra tiếng việt nhiều lúc đọc sẽ khó hiểu hơn là tiếng anh. Thân
     
    AC_Khanh01 and hieucocc like this.
  3. phamhuudu

    phamhuudu Verified User

    Bài viết:
    1,749
    Likes :
    727
    Waiting for Vietnamese version, and clear explaination about this article 8->
     
  4. Phú Nguyễn Hồng

    Phú Nguyễn Hồng Member

    Bài viết:
    113
    Likes :
    111
    MVC cũng dễ nếu ai đã từng viết asp mvc thì sẽ dễ dàng tiếp cận hơn vì đã có fw chuẩn. Trên đây chỉ là phần giới thiệu thôi, nếu post được cách tạo 1 controller cơ bản thì hay hơn nhiều :)

    PS: Nếu ai muốn bắt đầu với Zend FW và có thời gian tìm hiểu thì nên tìm các fw nhỏ như Codeigniter, Yii or Cake trước khi bắt đầu với Zend :)
     
  5. Mr.iCoder

    Mr.iCoder VIP Member

    Bài viết:
    523
    Likes :
    497
  6. hieucocc

    hieucocc Active Member

    Bài viết:
    409
    Likes :
    223
    thiệt đọc tiếng anh thích hơn đọc tiếng Pháp vs tiếng Nga :)
     
    Mr.iCoder thích bài này.
  7. AC_Khanh01

    AC_Khanh01 Member

    Bài viết:
    221
    Likes :
    61
    Mở 1 addons và xem code trong đó có vẻ dễ hiểu hơn chút @@
     
comments powered by Disqus

Chia sẻ trang này

Đang tải...