天生我才必有用

Drupal 文件系统

Posted in PHP    作者:Ray    2011年八月25日

Drupal7 的文件系统使用了3种自定义的URI,操作起来和访问http、ftp协议类似,比较直观。

  • public://
  • private://
  • temp://

用户还可以自己定义stream wrapper,来实现自己的URI。具体内容参见:DrupalStreamWrapperInterface。

当调用file_save_data时,有三种模式可以选择:

  • FILE_EXISTS_REPLACE:覆盖原有的文件
  • FILE_EXISTS_RENAME:对文件名从新命名,自动添加_1,_2等后缀。
  • FILE_EXISTS_ERROR:什么事情都不做,直接返回错误。

默认为FILE_EXISTS_RENAME模式。

如果保存成功则返回drupal的file对象。

标签:

Drupal Test Part 1

Posted in PHP    作者:Ray    2011年八月23日

最新的Drupal7提供了单元测试的功能,为你的代码健壮性提供了保证。

  1. 建立一个module.test的文件作为你模块的测试文件,module请替换成你的模块名称。
  2. 建立一个继承DrupalWebTestCase的类,并实现其中的getInfo的函数。
  3. 添加一个setUp的函数,这个函数类似所有单元测试中的setup函数,不过在这个函数中必须加入parent::setup(‘module’),其中module是你的模块名称。
  4. 在后台的激活testing模块。
  5. 在admin/config/development/testing/设定页面中,点击“Clean Environment”按钮,就可以在列表中看到你的测试模块了。
标签:

Drupal 7常用theme hooks

Posted in PHP    作者:Ray    2011年三月1日

file_link
Returns HTML for a link to a file.

html_tag
Returns HTML for a generic HTML tag with attributes. This can often be too generic a theme hook to use, but is really useful for adding a tag to the of a document or for theming a tag inside a render element.

image
Returns HTML for an image. image_style Returns HTML for an image using a specific image style.

item_list
Returns HTML for a list of items which can optionally be nested.

links
Returns HTML for a list of links (cannot be nested).

more_link
Returns HTML for a more link, often used on blocks.

pager
Returns HTML for a pager query element, a list of pages for result sets too long for one page.

progress_bar
Returns HTML for an indicator showing a task’s progress.

table
Returns HTML for a table.

username
Returns HTML for a username.

user_list
Returns HTML for a list of users.

user_picture
Returns HTML for a picture configured for the user’s account.

标签: ,