[documentation] [task] profile.module field clarification

Zen drupal-docs at drupal.org
Fri Jan 27 13:53:53 UTC 2006


Issue status update for 
http://drupal.org/node/46132
Post a follow up: 
http://drupal.org/project/comments/add/46132

-Project:      Drupal
+Project:      Documentation
 Version:      <none>
-Component:    profile.module
+Component:    Admin Guide
-Category:     feature requests
+Category:     tasks
 Priority:     minor
-Assigned to:  Zen
+Assigned to:  Anonymous
 Reported by:  drubeedoo
 Updated by:   Zen
 Status:       active

No worries drubeedoo. But I think this would be better off in the
documentation rather than the actual form. This doesn't affect normal
usage, and only crops up when users are either writing modules or
tinkering with PHP.


You could perhaps get it mentioned somewhere here [1].


Just for the record, the "-" is invalid here because when you say
$user->council-name, PHP thinks you are /subtracting/ 'name' from
'$user->council'. This is why '-' is invalid in variable names, as it
is an arithmetic operator.


Changing Project to Documentation.


Cheers :)
-K
[1] http://drupal.org/handbook/modules/profile




Zen



Previous comments:
------------------------------------------------------------------------

Tue, 24 Jan 2006 04:58:16 +0000 : drubeedoo

Creating unique fields like "council-officer" and
"council-officer-title" in profile.module 4.7b3 does not work, while
"profile_officer" and "profile_officer_title" work fine.  Though the
"profile_" prefix is recommended, I'm pretty darned sure that there are
no fields/variables named council-officer* anywhere in the bowels of
Drupal.


The reason for the renaming experiment was to have cleaner-reading URLs
like:  profile/council-officer-title instead of
profile/profile_officer_title.


*What's broken:*


/The fields are not accessible by name from user_profile.tpl.php unless
prefixed as profile_*/


My best guess is that something is hard-coded to look for the
"profile_" prefix somewhere in profile.module.


*Work-around:*


/Follow recommendations and prefix all fields in profile.module with
"profile_" in the name./




------------------------------------------------------------------------

Tue, 24 Jan 2006 05:11:47 +0000 : drubeedoo

*Clarification*


In user_profile.tpl.php the following does *not* work:



<?php print $user->council-test-field ?>




The following works fine:



<?php print $user->profile_test_field ?>






------------------------------------------------------------------------

Tue, 24 Jan 2006 20:47:42 +0000 : Zen

Hi drubeedoo,


  The issue is not because of the profile_ prefix or the council-
prefix. It is the - (hyphen) vs. the _ (underscore). 


You can:


a) Use underscores and make the problem go away.
b) Use a hyphen, but access it as an array rather than an object:
$user['council-officer-title'] will work whereas
$user->council-officer-title won't. You will very likely need to cast
your $user object into an array using: $user = (array)$user; (as an
e.g.).


Hope that made sense :) I'm going to mark this as closed. Please
re-open if need be.


Cheers :)
-K




------------------------------------------------------------------------

Wed, 25 Jan 2006 13:52:43 +0000 : mr700

Maybe profile.module should warn (if not deny) such use of characters
like '-' (and this should be a feature request)?




------------------------------------------------------------------------

Thu, 26 Jan 2006 21:11:18 +0000 : drubeedoo

Thanks for the reply, Zen.  I'm still a bit green when it comes to the
innards of Drupal and PHP.


mr700 has a good point.  The current explanation reads as follows:


"
The name of the field. The form name is not shown to the user but used
internally in the HTML code and URLs. Unless you know what you are
doing, it is highly recommended that you prefix the form name with
profile_ to avoid name clashes with other fields. Spaces or any other
special characters except dash (-) and underscore (_) are not allowed.
An example name is "profile_favorite_color" or perhaps just
"profile_color".


"
I would suggest changing it to the following:


"
The name of the field. The form name is not shown to the user but used
internally in the HTML code and URLs. It is highly recommended that you
prefix the form name with profile_ to avoid name clashes with other
fields. Spaces or any other special characters except underscore (_)
are not allowed, while use of dash (-) is for PHP experts only. An
example name is "profile_favorite_color" or perhaps just
"profile_color".


"
Thanks again for answering so quickly.  I have reopened this as a minor
feature request for your review.  Feel free to close it again if you
don't agree with the above.  I won't argue the point.






More information about the documentation mailing list