Template:Smcfunc/doc: Difference between revisions From Online Manual

Jump to: navigation, search
(Created page with "This template should be used for pages describing $smcFunc functions. The parameters are: {{parmdesc |function|d1=the name of the function described |usage|d2=how the functi...")
 
No edit summary
 
(3 intermediate revisions by the same user not shown)
Line 1: Line 1:
This template should be used for pages describing [[$smcFunc]] functions.
This template should be used for pages describing [[$smcFunc]] functions.


The parameters are:
Available parameters:
{{parmdesc
{{parmdesc
|function|d1=the name of the function described
|function|d1=the name of the function (e.g. ''db_query'')
|usage|d2=how the function is called with all the parameters that can be used
|order_position|d2=(optional) a number defining the order position for sorting purposes.
|description|d3=a short description of what the function does
|usage|d3=how the function is called with all the parameters available
|parameters|d4=a list of all the parameters with a short description, please use the {{tl|parmdesc}} to create the list
|description|d4=a description of what the function does and how it works
|example|d5=an example of how the function must be used, please use the <nowiki> and </nowiki> tag to surround the code block as described in the {{tl|code}} template documentation
|parameters|d5=a {{tl|parmdesc}} list of the parameters the function accepts and relative description
|return|d6=short description of what the function returns if anything is returned
|internal|d6=if set a box will remind the function is to be used only internally by the database abstraction layer
|return|d7=description of what the function returns if anything is returned
|notes|d8=additional notes if needed
|example|d9=an example of how the function must be used, please use the <nowiki> and </nowiki> tag to surround the code block as described in the {{tl|code}} template documentation
|additional fields|d10=tree additional fields where is possible to specify the name of the parameter and its content, to be used like in {{tl|parmdesc}}: <code><nowiki>|name of the field|d1=description of the field</nowiki></code>
}}
 
<pre><nowiki>
{{smcfunc
|function=db_query
|usage=$smcFunc['db_query'](identifier, query, values, connection)
|description=Works similar to how db_query worked in 1.x versions.
|parameters={{parmdesc
  |identifier|d1=is used to identify specific query types in which it is necessary to replace portions of the query for compatability across all Database Management Systems supported by SMF. The query must be written for MYSQL. The db_query function will alter the query.{{parmdesc
    |substring|d1=for the SQLite database, '''SUBSTRING''' will be replaced by '''SUBSTR'''
    |See the function smf_db_query|d2= in Subs-DB-{dbms}.php for the full list of replacements.
  }}
  |values|d2=is an array of values you are intending to use in the query.
}}
|return=a query resource or '''false''' on error.
|example=<nowiki>$result = $smcFunc['db_query'](''', '
SELECT poster_time
FROM {db_prefix}messages
WHERE id_msg = {int:id_msg}
LIMIT 1',
array(
'id_msg' => $user_settings['id_msg_last_visit'],
)
);</nowiki>
|Example with identifier 'substring'|d1=
{{code|1=<nowiki>$result = $smcFunc['db_query']('substring', '
SELECT m.subject,
'. ($mylimit > 0 ? SUBSTRING(m.body, 1, '.$mylimit.') as body  : 'm.body'). ',
IFNULL(mem.real_name, m.poster_name) AS realName, m.poster_time as date, mem.avatar, mem.posts, mem.date_registered as dateRegistered,mem.last_login as lastLogin,
IFNULL(a.id_attach, 0) AS ID_ATTACH, a.filename, a.attachment_type as attachmentType, t.id_board as category, b.name as category_name,
array(
'id_msg' => $user_settings['id_msg_last_visit'],
)
);</nowiki>}}
}}
 
</nowiki></pre>
will result in
{{smcfunc
|function=db_query
|usage=$smcFunc['db_query'] (identifier, query, values, connection)
|description=Works Similar to how db_query worked in 1.x versions.
|parameters={{parmdesc
  |identifier|d1=is used to identify specific query types in which it is necessary to replace portions of the query for compatability across all Database Management Systems supported by SMF. The query must be written for MYSQL. The db_query function will alter the query.{{parmdesc
    |substring|d1=for the SQLite database, '''SUBSTRING''' will be replaced by '''SUBSTR'''
    |See the function smf_db_query|d2= in Subs-DB-{dbms}.php for the full list of replacements.
  }}
  |values|d2=is an array of values you are intending to use in the query.
}}
|return=a query resource or '''false''' on error.
|example=<nowiki>$result = $smcFunc['db_query'](''', '
SELECT poster_time
FROM {db_prefix}messages
WHERE id_msg = {int:id_msg}
LIMIT 1',
array(
'id_msg' => $user_settings['id_msg_last_visit'],
)
);</nowiki>
|Example with identifier 'substring'|d1=
{{code|1=<nowiki>$result = $smcFunc['db_query']('substring', '
SELECT m.subject,
'. ($mylimit > 0 ? SUBSTRING(m.body, 1, '.$mylimit.') as body  : 'm.body'). ',
IFNULL(mem.real_name, m.poster_name) AS realName, m.poster_time as date, mem.avatar, mem.posts, mem.date_registered as dateRegistered,mem.last_login as lastLogin,
IFNULL(a.id_attach, 0) AS ID_ATTACH, a.filename, a.attachment_type as attachmentType, t.id_board as category, b.name as category_name,
array(
'id_msg' => $user_settings['id_msg_last_visit'],
)
);</nowiki>}}
}}
}}

Latest revision as of 07:51, 11 October 2012

This template should be used for pages describing $smcFunc functions.

Available parameters:

  • function the name of the function (e.g. db_query)
  • order_position (optional) a number defining the order position for sorting purposes.
  • usage how the function is called with all the parameters available
  • description a description of what the function does and how it works
  • parameters a {{parmdesc}} list of the parameters the function accepts and relative description
  • internal if set a box will remind the function is to be used only internally by the database abstraction layer
  • return description of what the function returns if anything is returned
  • notes additional notes if needed
  • example an example of how the function must be used, please use the <nowiki> and </nowiki> tag to surround the code block as described in the {{code}} template documentation
  • additional fields tree additional fields where is possible to specify the name of the parameter and its content, to be used like in {{parmdesc}}: |name of the field|d1=description of the field


{{smcfunc
|function=db_query
|usage=$smcFunc['db_query'](identifier, query, values, connection)
|description=Works similar to how db_query worked in 1.x versions.
|parameters={{parmdesc
  |identifier|d1=is used to identify specific query types in which it is necessary to replace portions of the query for compatability across all Database Management Systems supported by SMF. The query must be written for MYSQL. The db_query function will alter the query.{{parmdesc
    |substring|d1=for the SQLite database, '''SUBSTRING''' will be replaced by '''SUBSTR'''
    |See the function smf_db_query|d2= in Subs-DB-{dbms}.php for the full list of replacements.
  }}
  |values|d2=is an array of values you are intending to use in the query.
}}
|return=a query resource or '''false''' on error.
|example=<nowiki>$result = $smcFunc['db_query'](''', '
	SELECT poster_time
	FROM {db_prefix}messages
	WHERE id_msg = {int:id_msg}
	LIMIT 1',
	array(
		'id_msg' => $user_settings['id_msg_last_visit'],
	)
);
|Example with identifier 'substring'|d1=
{{code|1=$result = $smcFunc['db_query']('substring', '
	SELECT m.subject, 
		'. ($mylimit > 0 ? SUBSTRING(m.body, 1, '.$mylimit.') as body  : 'm.body'). ', 
		IFNULL(mem.real_name, m.poster_name) AS realName, m.poster_time as date, mem.avatar, mem.posts, mem.date_registered as dateRegistered,mem.last_login as lastLogin,
		IFNULL(a.id_attach, 0) AS ID_ATTACH, a.filename, a.attachment_type as attachmentType, t.id_board as category, b.name as category_name,
		array(
			'id_msg' => $user_settings['id_msg_last_visit'],
		)
	);}}
}}

</nowiki>

will result in {{smcfunc |function=db_query |usage=$smcFunc['db_query'] (identifier, query, values, connection) |description=Works Similar to how db_query worked in 1.x versions. |parameters={{parmdesc

 |identifier|d1=is used to identify specific query types in which it is necessary to replace portions of the query for compatability across all Database Management Systems supported by SMF. The query must be written for MYSQL. The db_query function will alter the query.{{parmdesc
   |substring|d1=for the SQLite database, SUBSTRING will be replaced by SUBSTR
   |See the function smf_db_query|d2= in Subs-DB-{dbms}.php for the full list of replacements.
 }}
 |values|d2=is an array of values you are intending to use in the query.

}} |return=a query resource or false on error. |example=$result = $smcFunc['db_query'](''', ' SELECT poster_time FROM {db_prefix}messages WHERE id_msg = {int:id_msg} LIMIT 1', array( 'id_msg' => $user_settings['id_msg_last_visit'], ) ); |Example with identifier 'substring'|d1=

$result = $smcFunc['db_query']('substring', '
	SELECT m.subject, 
		'. ($mylimit > 0 ? SUBSTRING(m.body, 1, '.$mylimit.') as body  : 'm.body'). ', 
		IFNULL(mem.real_name, m.poster_name) AS realName, m.poster_time as date, mem.avatar, mem.posts, mem.date_registered as dateRegistered,mem.last_login as lastLogin,
		IFNULL(a.id_attach, 0) AS ID_ATTACH, a.filename, a.attachment_type as attachmentType, t.id_board as category, b.name as category_name,
		array(
			'id_msg' => $user_settings['id_msg_last_visit'],
		)
	);

}}



Advertisement: