drupal--why $node->taxonomy is an array
someone wrote this code.
foreach ($node->taxonomy as $term) {
开发者_如何学JAVA$tids[] = 't.tid = %d';
$args[] = $term->tid;
}
how he knows that in foreach "$node->taxonomy" is an array? and when i loop it, foreach ($node->taxonomy as $term) { } the output that i get will be the $term's value. i don't know how it is change into the 't.tid = %d' and $term->tid. thank you.
In Drupal-related code, a $node
is almost always an object produced by the node_load()
function. Since every module has the opportunity to add its own properties to this object, it's very hard to find a central documentation of these properties.
By experience and by variable inspection, seasoned Drupal developers know that when set $node->taxonomy
is always an array of term object (as returned by the taxonomy_get_term()
function) indexed by their respective ids (named tids, for Term ID). This array is set by the taxonomy_nodeapi()
function when $op == 'load'
and is produced by the taxonomy_get_terms()
function.
The question give little information but we can guess that the loop is meant to build two arrays used to generate a database query that filter on the tid column matching those of the $node
object. Because the terms' data is already stored in the items of $node->taxonomy
, let's hope that this query is not used to re-load the terms to display some of their name and/or description. Collecting 't.tid = %d' is probably a bad idea, the query would be better build with a single "tid in (".
WHERE clause after collecting all the tids in db_placeholder($args)
.")"$args
.
The question is very unclear. All Items under the node object are arrays. You can check it yourself bu using:
print_r($node); die;
Or using any PHP debugger.
for the foreach, It is very simple foreach... I don't understand what is the problem with that.
t.tid is simply an SQL query. %d is a placeholder for $args[], which consists of $term->tid. It's like this structure: PDO connections.
精彩评论