简体   繁体   中英

What are Zend Framework modules?

I want to build a simple CRUD site using the framework but I'm confused with its file structure/concept. I understand the concept of MVC, I've done projects using CodeIgniter in the past. I'm following the tutorial on their official site , did a lot of configurations and tried creating a module into the skeleton app provided by them, no problem in doing so. So here are my questions,

  1. Is each module essentially a website? Do I create a new module in that Zend application folder each time I create a new website that uses the framework?

  2. Or, is each page/sub-page of a website a module ?

Before modules came out (that is to say before Zend 2), you had to manually declare folders containing different kind of controllers belonging to different containers (modules). It wasn't really handy of course and I'm pretty sure they've adopted the module system to be more like Symfony 2 which is module oriented.

A module isn't necessarily a website but can be a part of your website : for example, you can use one module for admin access and another one for public access.

Hope this will help you

From the ZF2 documenation

The module system is designed with flexibility, simplicity, and re-usability in mind. A module may contain just about anything: PHP code, including MVC functionality; library code; view scripts; and/or public assets such as images, CSS, and JavaScript. The possibilities are endless.

Answering in general for the MVC pattern.

A module is an isolated section of the website. Anything that you think can be broken down smaller should be. A module might be a sign up form that appears on a page (or several). It probably handles the submission of the form and passes a result back to be displayed on the page (including the form).

Another example of a common module is a menu bar. The code that organises the pages and generates the HTML for the menu would all make a module. The actual pages themselves are probably another module, and your menu module talks to your page module to get a list of pages that need outputting.

Any database table is generally a module. Anything that deals with interacting with that table goes through that module. The module is normally interrogated by other modules for information, or passed information to save in / remove from the table.

You can also have larger modules, such as a CMS page. That module is responsible for taking a slug and finding the page in the database. It would probably then ask several other modules to populate the page with content, telling them what page it needs to output. They would then go off and get the content for the page, generate their specific part of the page and pass it back to the original module, which puts it all together and returns the completed page HTML.

Frameworks will also come with various modules. I know Laravel comes with a module for registering and authenticating users. It has a module for accessing the database using an object-relational mapping method (Eloquent, this may be several modules pulled together I've not checked). Helpers are modules, for example a Form generator helper is a module.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM