Jambor-ee.com的ee建站24天

Jambor-ee.com正在进行一项伟大的行动,他们趁自己改版的空当,把自己的网站临时改成了一个ExpressionEngine教程发布中心。按他的计划他会在07年12月1日-24日建设一个网站,并且每天把他所做的工作写成教程发布出来,我们作为ee的学习者在这里把他们翻译出来,希望能对大家有点用~ =^0^=

Tuesday(星期二), January(一月) 01, 2008

第三天:建立数据模式~

ExpressionEngine的美妙之处就在于他的灵活性,他不会对你的内容显示,内容管理方式以及所添加的内容的形式做过多限制方式限制。


数据库()ee已经都帮我们建好了,我们今天所要做的就是为我们未来的菜谱们创建一些必要的字段,并且把这些字段和已有的数据库建立联系。ee已经为我们的这项工作提供了一个很好的工作界面(平台),那就是控制面板中Admin里的Weblog Administration页面,利用这一平台我们可以添加子站点、添加定制字段(custom field)、添加分类及分类组。分类组里也是可以有定制文件的。

分类管理

我们首先进入分类管理(Category Management)创建一个名叫“dietary needs”的分类组。之后我们马上就可以添加我们的分类了。一开始我打算给这个分类组添加以下分类:

  • Vegetarian
  • Vegan
  • Diabetes Friendly
  • Low Carb
  • Kid Friendly
  • Gluten Free

我们所要做的就是把你要添加的分类名称加进去,添加分类的同时,系统会为我们的分类自动制定一个url,在这个实例中我们不会使用任何其他的字段(fields)。
All we need to do is add the Category Name as the Category URL is added automatically自动 for us, and we aren’t going to use any of the other fields in this instance实例.  We may well add more later but this gives us enough data for now.  As you can see on the page that lists all the categories, you can order the categories alphabetically or choose a custom order by selecting the radio button “Custom” and using the up/down arrows to reorder them.

Now we’ll add some more category groups and categories.  I’m going to create more Category Groups called “Course” (Breakfast, Lunch, Dessert, Snack, etc) and another called “Cuisine” (Japanese, Italian, Indian, Mexican, etc).

Infact, we better add one more called (working title) “Occasions”.  In this group let’s add categories such as “Winter Recipes” (we need somewhere to add Colly’s stew!), “Christmas”, and “Party Food”.

Next up we’re going to add some custom fields to organise the data that makes up a recipe.

Custom Fields

Click “Custom Section Fields” and then “Create a New Section Field Group”.  We’re going to name our first field group “Recipes”.

Custom Fields (read about them thoroughly in the docs) allow you to describe your content and how it will be entered into the system using one of five field types (Text Input, Textarea, Dropdown List, Date Field, and Relationship).  As well as describing the content we can add some instructions to help the inputter, choose whether the content is required, and whether it will be searchable among other options.

For our recipes we’re going to break it up into the following fields:

Description (Field Name: ‘cf_recipes_description’).  This will be a textarea with the formatting ‘xhtml’.
Ingredients (Field Name: ‘cf_recipes_ings’).  This will be a textarea with the formatting ‘none’.  We’re going to make this into a list later using the List Maker plugin so make sure you add some instructions along the lines of “Please use a format similar to 1 tablespoon of Sugar and add each new ingredient on a new line.”
Directions (Field Name: ‘cf_recipes_directions’).  This will be a textarea with the formatting ‘xhtml’.
Serves (Field Name: ‘cf_recipes_serves’).  This will be a dropdown list with the formatting ‘none’.  In the box “Select Options” add the numbers 1 to 12 on new lines.
Prep Time (Field Name: ‘cf_recipes_prep’).  This will be a text input field with the formatting ‘none’.
Cooking Time (Field Name: ‘cf_recipes_cooking’).  This will again be a text input field with the formatting ‘none’.
So there we have our basic custom fields that describe the content that makes up a recipe.  We may add to these later once we start prototyping but for now, like with the category groups, they are enough to get us started.

You might be wondering about the field names I’ve given above.  At Erskine, now that our team is growing, we’re trying to get some structure into how we all do things.  Part of this structure is agree on naming conventions that we’ll all stick too.  The naming convention I’ve described above can be broken down into ‘the type of variable - in this case a custom field (cf), the sections that this custom field belongs to (recipes), and a description of the field.  This helps alot in your templates when you may be trying to differentiate between fresh variables, global variables, and custom field variables.

It doesn’t always work out as cleanly as this.  You may for example be using the same custom field group across a number of sections.  But in this case you should be able to come up with a generic grouping name for those sections to use when naming your custom fields.  Do you have any of your own naming conventions?

Custom Entry Statuses

Each section of our site can have it’s own custom status group or they can be shared another many sections.  The more you use statuses the more you’ll find them useful.  They could be used to make a feature out of certain content on the frontend, or they can be used to create a workflow for content publishers and editors in the control panel.

For now we’re simply going to create a new status groups called “Recipes” and add a new status called “Moderation”.  This means that we can set all user submitted recipes to this status and, even if we allow them to go live straight away, the administrators of the site will still be able to easily find submitted recipes and moderate them if required.

Section Management

The final part today is creating our first section.  Click “Section Management” and “Create a New Section”.

We’re creating the Recipes section so our Full Section Name is “Recipes” and the shortname is the lowercase “recipes”.  We’re not duplicating an existing section’s preferences but we are going to edit the group preferences.  Simply choose each of the category groups, the new entry status group, and the custom field group we just created.  We’re not going to create any new templates for this section yet (we’ll be doing that tomorrow!)

After you’ve submitted you’ll be able to edit more of the section’s preferences.  The only extra settings I’m going to change at this stage are the Path Settings.  I’ve decided on the following paths:

Section URL: /recipes/
Comment Page URL: /recipes/for/
Search Result URL: /recipes/for/
The label “Comment Page URL” is must be a throwback to when ExpressionEngine was just seen as a blogging platform.  What it’s describing is the URL of the single entry page i.e. where all the recipe’s content will be displayed, as opposed to the section URL which may list multiple recipes.  The first segment “recipes” will be the template group, and the segment “for” will be the template.  Hopefully this will be nice and readable in the URL - “recipes/for/homemade-cheesecake/”.

And that’s a wrap!

Almost anyway.  If you now hover over the Publish tab you’ll be able to choose to add some content to the Recipes section.  It might be a good idea if between now and tomorrow you add some test data.  Tomorrow we’ll be making a start on our templates and displaying some recipes!

Posted by =^0^= on 01/01 at 10:16 PM(下午)
translate • (0) Comments • (0) TrackbacksPermalink
Page 1 of 4 pages  1 2 3 >  Last(最后) »

The Author

Jamie Pittock's Avatar
Jamie Pittock
Jamie is a web technologist based in Yorkshire. He works for Erskine Design where he dances (and sometimes wrestles) with ExpressionEngine most days. He's doing his best at the moment to stop saying 'gosh'.