Orchestra入门-WordPress插件

tech2023-01-09  110

Here at Sitepoint our staff is lucky to be able to take advantage of what we call ‘Triple Time’. Three days a month are dedicated to working on personal web projects. This encourages people to expand on their skill sets and allows team members to put their heads together to create new and exciting web-related projects.

在Sitepoint,我们的员工很幸运能够利用我们称为“三重时间”的优势。 每月有三天致力于个人Web项目。 这鼓励人们扩展自己的技能,并允许团队成员共同努力以创建新的,令人兴奋的与Web相关的项目。

Michael Sauter used his Triple Time to develop this WordPress Plugin, tune in below to see what it’s all about! His plugin is available here.

迈克尔·索特(Michael Sauter)用他的Triple Time开发了这个WordPress插件,请收看下面的内容,以了解一切! 他的插件在这里可用。

Get Started with Orchestra – WordPress Plugin

乐团入门– WordPress插件

For JumpCast transcription and more like this, visit Learnable

有关JumpCast转录以及更多类似内容,请访问Learnable

    Jess: I’m here today with Michael Sauter, who is a web developer at SitePoint. He’s going to tell us a little about a WordPress plugin that he has created called Orchestra. What can you tell us about Orchestra?

杰西:我今天和SitePoint的Web开发人员迈克尔·索特(Michael Sauter)在一起。 他将向我们介绍他创建的一个名为Orchestra的WordPress插件。 您能告诉我们有关乐团的哪些信息?

Michael: Orchestra is a WordPress plugin that allows you to write other WordPress plugins. So if you have anything complex to do in a WordPress plugin in the admin area – if you have lots of forms, you need to do lots of things, not just have a setting or two, then WordPress actually provides you with very little help in how to write it and how to structure your plugin.

迈克尔:乐团是一个WordPress插件,可让您编写其他WordPress插件。 因此,如果您需要在管理区域的WordPress插件中完成任何复杂的工作–如果您有很多表格,则需要做很多事情,而不仅仅是一两个设置,那么WordPress实际上在为您提供的帮助很少如何编写以及如何构建插件。

So what I did is, I gathered components from other frameworks that make it a lot easier to write more complex codes. So, for example, dealing with databases, working with forms. So I’ve wired these components together, put them in a WordPress plugin. Once that plugin is installed, you can write your own plugins on top of this plugin and use the structure and all the help it provides.

所以我要做的是,我从其他框架中收集了一些组件,这些组件使编写更复杂的代码变得容易得多。 因此,例如,处理数据库,处理表单。 因此,我将这些组件连接在一起,并将它们放在WordPress插件中。 一旦安装了该插件,您就可以在该插件之上编写自己的插件,并使用该结构及其提供的所有帮助。

Jess: So how did you come up with the idea for Orchestra then?

杰西:那你是怎么想到乐团的呢?

Michael: So at Sitepoint, I needed to write a WordPress plugin that was really complex. So you couldn’t just add a setting. You needed to have a complex interface with lots of forms that are dynamic, and you needed to interact with the database. And I didn’t want to do all the sanitisation and everything on my own. So I thought there are other frameworks that are really good, and that make it really easy to do that, and that are also a lot easier to maintain. So I just decided to wire these components together and then write my plugin that I needed to write on top of that.

迈克尔:所以在Sitepoint,我需要编写一个非常复杂的WordPress插件。 因此,您不能只添加设置。 您需要具有许多具有动态形式的复杂界面,并且需要与数据库进行交互。 而且我不想自己做所有的消毒工作。 因此,我认为还有其他一些非常好的框架,这些框架非常容易实现,并且维护起来也容易得多。 因此,我决定将这些组件连接在一起,然后编写我需要在上面编写的插件。

Jess: Who can use Orchestra then?

杰西:谁可以使用乐团?

Michael: Basically, everyone can use Orchestra who needs to write a WordPress plugin. But it is built on modern PHP libraries that require PHP 5.3. So for example, it uses Symfony2 components, Doctrine components. So your web server needs PHP 5.3. Also, if you haven’t dealt with namespaces and lots of new features in PHP 5.3, it will be a very steep learning curve.

迈克尔:基本上,每个人都可以使用需要编写WordPress插件的Orchestra。 但是它建立在需要PHP 5.3的现代PHP库上。 因此,例如,它使用Symfony2组件,Doctrine组件。 因此,您的Web服务器需要PHP 5.3。 另外,如果您没有处理名称空间和PHP 5.3中的许多新功能,那将是一条非常陡峭的学习曲线。

Jess: How do you go about using it then?

杰西:那你该如何使用呢?

Michael: So Orchestra comes with a command, that you write the command line that lets you create a new plugin. Basically, it sets up the structure and includes a demo. So you create it, and then you go on just changing it to what you need, adding new entities, adding new controllers, adding new views.

Michael:Orchestra附带了一个命令,您可以编写命令行来创建新插件。 基本上,它设置了结构并包括一个演示。 因此,您创建了它,然后继续将其更改为所需的内容,添加了新实体,添加了新控制器,添加了新视图。

Jess: Can you show us how to do that? Can you put together a screencast, maybe? Show everyone how it works.

杰西:你能告诉我们怎么做吗? 可以进行屏幕录像了吗? 向所有人展示其工作原理。

Michael: Yeah, sure.

迈克尔:是的,当然。

Jess: Cool. Let’s have a look at that.

杰西:很酷。 让我们来看看。

Michael: I have already installed WordPress, and I have put the Orchestra plugin inside wp-content/plugins folder. Now I’m going to show how you can use it to create your own plugin. So in the terminal, we go to the plugins folder. And then type in “orchestra/console” and there is one command to create plugins. So plugin key and then your name. We’ll call this “demo”.

迈克尔:我已经安装了WordPress,并将Orchestra插件放在wp-content / plugins文件夹中。 现在,我将展示如何使用它来创建自己的插件。 因此,在终端中,我们转到plugins文件夹。 然后输入“ orchestra / console”,有一个命令可以创建插件。 因此,插件密钥,然后是您的名字。 我们将其称为“演示”。

So this has created a demo plugin in the folder, “demo” You can see it’s up here. What we now need to do is to activate the plugin in the plugin setting in WordPress. So you need to refresh that, and the demo shows up here… and we activate the plugin. You can see there’s already a page in here. But you also need to tell this to update the database. And I’ll show you what this will do. So in demo, there is a bit of code already in there. We model what will be in the database in “Entity”, and I created a person in there. So this will create a table which represents “wp_demo_persons.” And a person has an ID and a name. So when we now tell Doctrine, the object relational manager, to update the schema. We’ll do that. I will just paste that in and update it. So this schema is updated. If we look into our database, we should see a new table here. It’s there. It has an ID and a name.

这样就在文件夹“ demo”中创建了一个演示插件。您可以在此处看到它。 我们现在需要做的是在WordPress的插件设置中激活该插件。 因此,您需要刷新它,并且此示例将在此处显示。。。我们激活了该插件。 您可以看到这里已经有一个页面。 但是您还需要告诉它更新数据库。 我会告诉你这将做什么。 因此在演示中,已经有一些代码了。 我们在“实体”中对数据库进行建模,然后在其中创建一个人。 因此,这将创建一个表示“ wp_demo_persons”的表。 一个人有一个ID和一个名字。 因此,当我们现在告诉对象关系管理器Doctrine更新架构时。 我们会做到的。 我将其粘贴并更新。 因此,此架构已更新。 如果我们查看数据库,则应该在此处看到一个新表。 在那里。 它具有一个ID和一个名称。

There’s nothing yet in there, but we can now use the demo plugin to edit, to add new persons to edit existing persons. So as the demo plugin is structured around the MVC pattern we can see here in the default controller, we have index action. So this will get all the persons that are in the database. It will then pass those persons to the default template. Let’s see how it looks. So we go to demo. This, will call the default controller and the index action. There is no person there yet. We then go to “create new person”. And then we will see a form where we can enter “John Doe,” for example. Click “create” and we have created a new entry in here. In the database that’s just ID 1 with name “John Doe”. The form is set up in the “create action”, which is called, so we create a new empty person object, we create a form for it. If we use the POST method to this “create action”, we find the new values in the form, check if it’s valid. If it is, it goes right to the database, and let’s us know that it has happened in the flash, and redirect to the index.

那里什么都没有,但是我们现在可以使用演示插件进行编辑,添加新人员来编辑现有人员。 因此,由于演示插件是围绕MVC模式构建的,因此我们可以在默认控制器中看到此处,我们具有索引操作。 因此,这将获取数据库中的所有人员。 然后它将把这些人传递给默认模板。 让我们看看它的外观。 所以我们去演示。 这将调用默认控制器和索引动作。 那里还没有人。 然后,我们去“创建新人”。 然后,我们将看到一个表单,可以在其中输入“ John Doe”。 点击“创建”,我们在这里创建了一个新条目。 在只有ID 1的数据库中,名称为“ John Doe”。 该表单是在“创建动作”(称为“创建动作”)中设置的,因此我们创建了一个新的空人对象,并为此创建了一个表单。 如果我们对这种“创建动作”使用POST方法,则会在表单中找到新值,并检查其是否有效。 如果是这样,它将直接进入数据库,并让我们知道它已在闪存中发生,然后重定向到索引。

So that’s what you see here. “Person created,” redirect to index. Similar thing for edit. I’ll show you how the template works. For edit, same thing. You create a form. Set the model for it, and then you render the HTML, you pass it the form and the ID. So the view is Default/edit.html.twig. which looks like that. So we have a form action, it points to the default/edit action. And we render that form here… Edit it and say “John Doe 2”. That will edit the person. And we can also delete it.

这就是您在这里看到的。 “已创建人员”,重定向到索引。 类似的东西进行编辑。 我将向您展示该模板的工作方式。 对于编辑,同样。 您创建一个窗体。 为其设置模型,然后呈现HTML,将其传递给表单和ID。 因此,视图为Default / edit.html.twig。 看起来像那样。 因此,我们有一个表单动作,它指向默认/编辑动作。 然后我们在此处渲染该表格…编辑它并说“ John Doe 2”。 那将编辑该人。 我们也可以删除它。

Basically, that’s the structure of a new plugin. So you have controllers, entity, the forms. And you can change it to whatever you like and use the console to update your database.

基本上,这就是新插件的结构。 因此,您将拥有控制器,实体,表格。 您可以将其更改为所需的任何内容,并使用控制台更新数据库。

Jess: Cool. So that’s how you use Orchestra. If you want to learn more, where can people check things out?

杰西:很酷。 这就是您使用乐队的方式。 如果您想了解更多信息,人们可以在哪里检查?

Michael: Basically, as Orchestra is a set of components that are already available everywhere and also very well documented, like you can in Orchestra and the documentation for these parts. Basically, you can consult the Symfony2 documentation, which is very well written. There’s lots of documentation about Doctrine as well, and same goes for Twig. Basically, everything in Orchestra is covered online, so you can read the documentation. The only part that is custom in Orchestra that I wrote is the controller and router. That is modeled around Symfony2 controller. So for the most part, you can just use that documentation, and you’re good to go.

迈克尔:基本上,乐团是一套组件,已经随处可见,而且文档也很好,就像您在乐团中以及这些零件的文档一样。 基本上,您可以查阅Symfony2文档,该文档写得很好。 关于教义的文档也很多,Twig也是如此。 基本上,乐团中的所有内容都在线涵盖,因此您可以阅读文档。 我编写的Orchestra中唯一自定义的部分是控制器和路由器。 这是围绕Symfony2控制器建模的。 因此,在大多数情况下,您只需使用该文档,就可以了。

Jess: Too easy. Thanks so much, Michael. This has been Jess Genevieve Brown with Michael Sauter for SitePoint.com

杰西:太容易了。 非常感谢Michael。 这是Sitepoint.com的Michael Sauter的Jess Genevieve Brown

Michael’s plugin is available here.

迈克尔的插件在这里可用。

翻译自: https://www.sitepoint.com/get-started-with-orchestra/

相关资源:jdk-8u281-windows-x64.exe
最新回复(0)