简体   繁体   English

Drupal-显示表单更改内容

[英]Drupal - Display form alter content

I have created a module with a hook_form_alter that adds an extra field called 'Phone', this gives the site administrator the ability to modify a site phone number. 我创建了一个带有hook_form_alter的模块,该模块添加了一个名为“电话”的额外字段,这使站点管理员可以修改站点电话号码。

Is there a way I can access this field data without an SQL query? 有没有一种方法可以在没有 SQL查询的情况下访问此字段数据?

Thanks 谢谢

If you mean without an SQL statement being executed at all then no, you need to store the data somewhere you can retrieve it later. 如果您的意思是根本不执行SQL语句,则否,那么您需要将数据存储在可以稍后检索的位置。 I suppose you could use a flat file if you're desperate but since Drupal relies on the database (so it'll always be there) I don't see any value to this. 我想如果您不顾一切就可以使用一个平面文件,但是由于Drupal依赖数据库(因此它将始终存在),因此我看不到任何价值。

If you're only bothered about not having to write SQL yourself then you can use the variable system, for which Drupal will handle the database calls. 如果只为不必自己编写SQL而烦恼,则可以使用变量系统,Drupal将为此变量系统处理数据库调用。

// Set a variable
variable_set('site_phone_number', $the_number);

// Retrieve the variable
variable_get('site_phone_number', $default_if_variable_doesnt_exist);

variable_get() docs
variable_set() docs

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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