wordpress框架_WordPress作为框架

wordpress框架

WordPress is one of the most popular CMS (Content Management Systems) as far as the user base and ease of access is concerned. Many famous content rich websites use WordPress as their back-end – including SitePoint itself. Regular updates, a larger community, great support forum, rich documentation and many other factors have put WP way ahead of its competitors.

就用户群和易用性而言,WordPress是最受欢迎的CMS(内容管理系统)之一。 许多著名的内容丰富的网站都使用WordPress作为后端-包括SitePoint本身。 定期更新,庞大的社区,强大的支持论坛,丰富的文档资料以及许多其他因素使WP领先于竞争对手。

The first thing that comes to most people’s minds when thinking of WordPress is Blog or Content Management Platform, but there is another angle to it. Have you considered that it can act as a full framework for developing web applications as well?

当想到WordPress时,大多数人想到的第一件事是Blog或Content Management Platform,但它有另一个角度。 您是否考虑过它也可以作为开发Web应用程序的完整框架?

There are various aspects which are taken into consideration before choosing a framework for web development. In this piece, we are going to look into features that WP provides if we treat it as a web development framework.

在选择Web开发框架之前,需要考虑各个方面。 在本文中,如果将WP视为Web开发框架,我们将研究WP提供的功能。

社区,支持和文档 (Community, Support and Documentation)

WordPress has a great community and an active support forum. Whether it is an issue with installation, setting up, development or anything else, everything is timely resolved by the support community. The WordPress Codex is a community moderated wiki which is regularly updated. Documentation is the first thing you need when learning any new language or framework, and the codex provides just that. While most, if not all, other frameworks also sport these features, it’s important to note that WP does too, thus not lagging behind.

WordPress有一个很棒的社区和一个活跃的支持论坛。 无论是安装,设置,开发还是其他问题, 支持社区都会及时解决。 WordPress Codex是社区管理的Wiki,它会定期更新。 学习任何新的语言或框架时,文档是您需要的第一件事,而法典恰恰提供了这一点。 尽管大多数(如果不是全部)其他框架也具有这些功能,但需要注意的是WP也具有这些功能,因此不会落后。

用户管理 (User Management)

WordPress has an excellent user management module which takes care of all the functionality such as user registration and login, user role management, assigning capabilities to different roles and creating new roles. This functionality can be further enhanced by using plugins like the Capability Manager which also provides all the above features without you having to worry about session management or security issues.

WordPress具有出色的用户管理模块,该模块负责所有功能,例如用户注册和登录,用户角色管理,为不同角色分配功能以及创建新角色。 可以使用功能管理器之类的插件进一步增强此功能,该插件还提供上述所有功能,而您不必担心会话管理或安全性问题。

If we talk about other frameworks, most provide some sort of User Management solution – for example, Yii provides a user management extension known as Yii-User and similarly for CodeIgniter framework, you`ll find a user management control panel named BackendPro which you can easily integrate into your CI project.

如果我们谈论其他框架,则大多数都提供了某种用户管理解决方案–例如,Yii提供了一个称为Yii-User的用户管理扩展,对于CodeIgniter框架也是如此 ,您将找到一个名为BackendPro的用户管理控制面板,您可以轻松集成到您的CI项目中。

管理仪表盘 (Admin Dashboard)

Who wouldn’t love their application having an easy to use admin panel through which the front-end content could be managed? WP provides a ready to use back-end panel which has most of the options you might need. In addition to it, you can create your own custom setting pages for a wide set of requirements. One more perk is that you don`t have to worry about back-end styling at all – WP comes with its own set of styles for the back-end panel.

谁会不喜欢他们的应用程序具有易于使用的管理面板来管理前端内容? WP提供了一个随时可用的后端面板,其中包含您可能需要的大多数选项。 除此之外,您还可以创建自己的自定义设置页面来满足各种要求。 另一个好处是,您完全不必担心后端样式-WP带有自己的后端面板样式集。

The Admin Dashboard is the part that lacks in other frameworks. Symfony and Yii provide a couple of extensions for their respective frameworks through which you can generate the Admin UI, but the functionality part is left up to you. This is one area in which having a CMS is advantageous, but can cause significant overhead if it lacks the features you need, and has features you don’t.

管理仪表板是其他框架中缺少的部分。 Symfony和Yii为它们各自的框架提供了几个扩展,您可以通过它们生成管理UI,但是功能部分由您自己决定。 这是拥有CMS的优势所在,但是如果缺少所需的功能而又没有所需的功能,则可能导致大量开销。

CRUD(创建读取更新删除)操作 (CRUD (Create Read Update Delete) Operation)

Most people appreciate a framework’s help in performing these basic operations, so picking one that makes it easy is often a deciding factor for many developers.

大多数人都喜欢框架在执行这些基本操作方面的帮助,因此,选择易于使用的框架通常是许多开发人员的决定因素。

Lets try to relate this with the real world a bit. As far as WordPress is concerned, everything is a post. A book is a post, a person is a post, and any distinguishable entity is a post. WordPress calls them Custom Post Types.

让我们尝试将此与现实世界联系起来。 就WordPress而言,一切都是帖子。 一本书是一个职位,一个人是一个职位,任何可区分的实体都是一个职位。 WordPress将其称为“ 自定义帖子类型”

Let us take an example of Book for now. If you tell WordPress that you want to define a post type named “Book” for your application, you will automatically get all the CRUD bundled with it.

现在让我们以Book为例。 如果您告诉WordPress您想要为应用程序定义一个名为“ Book”的帖子类型,您将自动将所有CRUD捆绑在一起。

  • Add / Update Book – This will be the default WordPress post edit screen for adding / updating books.

    添加/更新书籍–这将是添加/更新书籍的默认WordPress帖子编辑屏幕。
  • View / Delete Books – This will be the book listing page with delete option as well.

    查看/删除图书–这也是带有删除选项的图书清单页面。
add_action( 'init', 'create_post_type' );
    function create_post_type() {
            register_post_type( 'book',
            array(
              'labels' => array(
                 'name' => __( 'Books' ),
                 'singular_name' => __( 'Book' )
              ),
            'public' => true,
            'has_archive' => true,
            )
        );
    }

The above code snippet does all the magic behind it, and the CRUD operation is generated for the book post type. You do not have to write SQL queries for this, rather focusing on the business logic, making the development truly rapid.

上面的代码段发挥了所有作用,并且为书帖类型生成了CRUD操作。 您不必为此编写SQL查询,而专注于业务逻辑,从而使开发真正快速。

Considering other frameworks, Yii dominates with its very easy to use GUI CRUD Generator followed by the GroceryCrud module for CodeIgniter and then scaffolding in CakePHP. True, the nitty gritty fine tuning of CRUD operations and database relations is still up to you, but when wanting to get off the ground fast and improve later, these solutions come second to none.

考虑其他框架,Yii以其易于使用的GUI CRUD Generator占主导地位,其后是CodeIgniter的GroceryCrud模块,然后是CakePHP的脚手架。 的确,对CRUD操作和数据库关系的精确调整仍然取决于您,但是当您希望快速起步并在以后进行改进时,这些解决方案将是无与伦比的。

上传和媒体管理 (Uploads and Media Management)

File upload and media management is a must for all modern day frameworks as you cannot think of any application which does not have media support these days – whether it is images, music or videos. WordPress has an integrated media library (these media files are nothing but attachment post types as we have discussed above) through which you can upload media and perform various operations such as cropping, flipping, resizing etc.

文件上传和媒体管理对于所有现代框架都是必不可少的,因为您无法想到如今没有媒体支持的任何应用程序-无论是图像,音乐还是视频。 WordPress具有集成的媒体库(这些媒体文件只不过是我们上面讨论的附件类型),通过它您可以上传媒体并执行各种操作,例如裁剪,翻转,调整大小等。

WordPress image functions allow users to use the uploaded images anywhere in the front-end with all the modification flexibility from your side. You can even create a gallery of images in the back-end and display it in the front-end.

WordPress图像功能允许用户在前端的任何位置使用上传的图像,并且可以从您身边进行所有修改。 您甚至可以在后端创建图像库,并在前端显示它。

If we look outside WordPress, Symfony and Yii also provide cool extensions for media and file upload management, but objectively, none as rich as a fully formed CMS like WordPress. This takes a huge chunk of manual development of your time, allowing you to focus on the business critical parts first.

如果我们在WordPress之外浏览, SymfonyYii还为媒体和文件上传管理提供了很酷的扩展,但是客观地讲,没有像WordPress这样的格式完整的CMS丰富。 这需要您花费大量时间进行手动开发,因此您可以首先专注于业务关键部分。

可扩展性和可扩展性 (Extensibility and scalability)

From a developer’s point of view, extensibility and scalability are a very important part of every framework. Hooks and Filters are what make WordPress a powerful framework for development.

从开发人员的角度来看,可扩展性和可伸缩性是每个框架的重要组成部分。 钩子过滤器使WordPress成为强大的开发框架。

筛选器 (Filters)

If you want to change the output of some default functionality, just pass it to your custom filter and output anything you want. Suppose you are managing a directory website (with lists of all types of books) with their respective prices, and you want to increase the appeared price of every book by $10. This will be the filter you`ll write.

如果要更改某些默认功能的输出,只需将其传递到自定义过滤器并输出所需的任何内容即可。 假设您正在管理一个目录网站(包含所有类型的书籍的清单)及其各自的价格,并且您希望将每本书籍的显示价格提高10美元。 这将是您将要编写的过滤器。

add_filter('book_price','custom_book_price');
    function custom_book_price($book_price){
        $book_price = $book_price + 10;
        return $book_price;
    }

The above code will add $10 to the price of each book and will show in the view. Filters are present in every high quality modern framework and templating engine.

上面的代码将为每本书的价格增加10美元,并显示在视图中。 过滤器存在于每个高质量的现代框架和模板引擎中。

钩子 (Hooks)

Hooks are nothing but custom function calls at specific points in the WordPress code execution chain. You can even think of them as triggers. Suppose you want to be notified via email whenever a new entry is created in your application. For this you will hook a custom function up to the default publish_post hook of WordPress.

钩子不过是WordPress代码执行链中特定点的自定义函数调用。 您甚至可以将它们视为触发器。 假设您希望在应用程序中创建新条目时通过电子邮件收到通知。 为此,您需要将自定义函数挂钩到WordPress的默认publish_post挂钩。

add_action('publish_post','custom_mail_admin');

add_action('publish_post','custom_mail_admin');

Now all you need to do is implement the function custom_mail_admin and it will get executed automatically whenever a new post is published.

现在,您所需要做的就是实现函数custom_mail_admin ,只要发布新帖子,它将自动执行。

Hooks and Filters together are a powerful duo, and one of the main reasons of WordPress’ successful evolution into a web development framework for so many companies.

挂钩和筛选器是一个强大的工具,也是WordPress成功发展为众多公司的Web开发框架的主要原因之一。

To a certain degree, hooks are supported in all major frameworks, but vary in trigger times. Obviously, a framework like, for example, Kohana won’t have a “publish_post” hook, but might have a “post-controller” hook (it does – in the form of system.post-controller) which executes after a controller is finished performing its action.

在某种程度上,所有主要框架都支持钩子,但是触发时间有所不同。 显然,例如Kohana之类的框架将没有“ publish_post”钩子,但可能会有一个“ post-controller”钩子(它以system.post-controller的形式),该钩子在控制器被执行后执行完成其动作。

URL路由和SEO友好URL (URL Routing and SEO Friendly URLs)

A very important parameter if you are looking towards building a news/content application or website. The URL structure plays a very important role in SEO as we all know, and WordPress has a powerful Permalink functionality through which you can have different types of permalinks for content or pages depending on your requirements.

如果您要构建新闻/内容应用程序或网站,则这是一个非常重要的参数。 众所周知,URL结构在SEO中起着非常重要的作用,而WordPress具有强大的永久链接功能,通过它您可以根据需要为内容或页面设置不同类型的永久链接。

URL rewriting also plays a crucial role in a complex web application where your URL contains many GET parameters and the URL becomes too long and complex. Like many frameworks, WordPress provides a Rewrite API through which you can play with the URL structure and customize it as per your requirements, though admittedly, WP does this in an incredibly user friendly manner.

URL重写在复杂的Web应用程序中也起着至关重要的作用,在该Web应用程序中,URL包含许多GET参数,并且URL变得太长和复杂。 像许多框架一样,WordPress提供了一个Rewrite API,通过它您可以使用URL结构并根据您的要求对其进行自定义,不过诚然,WP以一种非常用户友好的方式来做到这一点。

Almost all frameworks support URL routing, among which Laravel provides a decent user-friendly routing API followed by Yii, Zend, CakePHP and others.

几乎所有框架都支持URL路由,其中Laravel提供了一个不错的用户友好的路由API,其后是YiiZendCakePHP等。

快取 (Caching)

If you are looking at a high performance application serving millions of users, you need to have a caching mechanism in place. WordPress has a built in Transient API which provides database level caching functionality to be used in your application. If you are looking for a more advanced caching mechanism with all the controls in your hand, then plugins like W3 Total Cache will serve this purpose. Use this way to manage cache without much overhead.

如果您正在寻找可为数百万用户提供服务的高性能应用程序,则需要适当的缓存机制。 WordPress具有内置的Transient API ,该API提供了可在您的应用程序中使用的数据库级缓存功能。 如果您正在寻找一种更高级的缓存机制,并且希望掌握所有控件,那么W3 Total Cache之类的插件将可以实现此目的。 使用这种方式来管理缓存而没有太多开销。

Again, most frameworks support this. Some examples include Yii and Laravel, both of which provide a very easy caching mechanism, arguably better than WordPress’, through which you can boost you application’s performance.

同样,大多数框架都支持这一点。 包括YiiLaravel在内的一些示例,它们都提供了一种非常简单的缓存机制,可以说比WordPress更好,可以通过它们提高应用程序的性能。

范本 (Templates)

WordPress Templates deal with presenting your content. If you are familiar with the MVC architecture, you can relate templates to views. One page can be assigned multiple templates. So even if data is same, the styling will vary.

WordPress模板负责呈现您的内容。 如果您熟悉MVC架构,则可以将模板与视图相关联。 一页可以分配多个模板。 因此,即使数据相同,样式也会有所不同。

Considering other frameworks, Laravel and Phalcon have amazing templating engines built in, while other frameworks have their own solutions as well.

考虑其他框架, LaravelPhalcon内置了惊人的模板引擎,而其他框架也有自己的解决方案。

MVC呢? (What about MVC ?)

These were all the major features that make WordPress a complete web application development framework if we compare it to the other frameworks on the market, but what about MVC? Almost every web framework nowadays follows the MVC architecture. Indeed, WordPress does not follow this architecture due to dedicated support for backwards compatibility with older deployments. In spite of this, efforts are being made to make WP follow the MVC pattern – you can check out WP MVC and Tina MVC.

如果将WordPress与市场上的其他框架进行比较,这些都是使WordPress成为完整的Web应用程序开发框架的所有主要功能,但是MVC呢? 如今,几乎每个Web框架都遵循MVC架构。 的确,由于专用于对较早部署的向后兼容性的支持,WordPress并未遵循此体系结构。 尽管如此,我们仍在努力使WP遵循MVC模式-您可以查看WP MVCTina MVC

结论 (Conclusion)

WordPress is by no means a drop-in replacement for other frameworks, but makes for a decent alternative, providing most, if not all features covered by already popular frameworks. One thing to be worried about is its performance and overhead due to functions you may not exactly be needing for your particular app, but as far as developing functionality in it goes – WordPress can indeed rival some of the best frameworks out there, even if it is “just” a CMS.

WordPress绝不是其他框架的直接替代品,而是一个不错的选择,提供了已经流行的框架涵盖的大多数(如果不是全部)功能。 需要担心的一件事是它的性能和开销,这可能是因为您可能不是特定应用程序确实需要的功能,但是就其开发功能而言,WordPress确实可以与其中的一些最佳框架相提并论。是CMS。

Hope you enjoyed reading the article. Comments are welcome!

希望您喜欢阅读本文。 欢迎发表评论!

翻译自: https://www.sitepoint.com/wordpress-framework/

wordpress框架

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值