简体   繁体   English

Node.tpl字段的Drupal 6 php包含而不是等于

[英]Drupal 6 php for node.tpl field contains rather than equal to

I've edited my question as a response to the first commenter. 我已经编辑了我的问题,作为对第一位评论者的回复。

I'm new to PHP and Drupal templates and an not an experienced programmer. 我是PHP和Drupal模板的新手,并且不是经验丰富的程序员。

My organization has events throughout the year. 我的组织全年都有活动。 For each event we make recordings, speakers slides and other materials available to either anonymous users or just our members (a custom role). 对于每个事件,我们都会为匿名用户或我们的成员(自定义角色)提供录音,演讲者幻灯片和其他材料。 Each event has multiple files and whether they're made available to anonymous users or our members is made a file-by-file basis. 每个事件都有多个文件,是否将其提供给匿名用户或我们的成员使用,将逐个文件进行。 So an event can have certain files available to anonymous users and others available only to our members. 因此,活动可以使匿名用户可以使用某些文件,而仅我们的成员可以使用其他文件。

We're using the ImageField Extended Fields module to add fields to file uploads and have a checkbox called "Make Public" along with "Description" and "Sort Order" (which I'm hoping can be used to order the files for display on the page... but that's not a priority). 我们正在使用ImageField扩展字段模块将字段添加到文件上传中,并具有一个名为“公开”的复选框以及“描述”和“排序顺序”(我希望可以用来对文件进行排序以显示在页面...但这不是优先事项)。 A content editor will check the box to make the file available to anonymous users but the default is just for our members. 内容编辑器将选中该框,以使该文件可用于匿名用户,但默认设置仅适用于我们的成员。

The first commenter said the field contents look like a serialized array: 第一位评论者说,字段内容看起来像一个序列化数组:

a:3:{s:11:"description";s:50:"text text text text text";s:19:"fapi_sort_order_key";a:3:{s:4:"body";s:1:"1";s:6:"format";i:0;s:5:"style";s:9:"textfield";}s:29:"workflow_fapi_make_public_key";i:1;}

I would like to evaluate this field to see whether the "workflow_fapi_make_public_key" portion is 1 or 0 and have the node.tpl.php file display differently depending on the results. 我想评估此字段,以查看“ workflow_fapi_make_public_key”部分是1还是0,并根据结果显示不同的node.tpl.php文件。

I started with 我开始

<?php if ($node->field_eli_event_files_data[0]) : ?>

then moved on to 然后继续

<?php if (strpos($node->field_eli_event_files_data, '"workflow_fapi_make_public_key";i:0') !== FALSE) : ?>
  <h1>Hi there!</h1> 
<?php endif; ?>

. The latter statement always came up as false. 后者的陈述总是错误的。

Any advice as to how this can be best accomplished would be greatly appreciated. 关于如何最好地实现这一点的任何建议将不胜感激。

Thanks. 谢谢。

The value of the field that you have submitted is the serialized form found in the database, ie a string used to store the value of a complex variable - an array in this case - in a single database text field. 您提交的字段的值是在数据库中找到的序列化表格,即用于在单个数据库文本字段中存储复杂变量(在这种情况下为数组)的值的字符串。 You won't find this string anywhere in the node object. 在节点对象的任何地方都找不到此字符串。 If you need more information on that, please refer to serialize() and unserialize() functions documentation in the php.net site. 如果您需要更多信息,请参阅php.net网站中的serialize()unserialize()函数文档。

If you need to test the value of workflow_fapi_make_public_key you will find it in $node->field_IMAGEFIELD_NAME[0]['data']['workflow_fapi_make_public_key'] (you should verify this via Devel module or another way to inspect the node's content). 如果需要测试workflow_fapi_make_public_key $node->field_IMAGEFIELD_NAME[0]['data']['workflow_fapi_make_public_key']的值,则可以在$node->field_IMAGEFIELD_NAME[0]['data']['workflow_fapi_make_public_key']找到它(您应通过Devel模块或其他检查节点内容的方法对此进行验证)。

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

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