📄 03-user.sgml
字号:
<!-- $Id: 03-user.sgml,v 1.1.1.1 2000/04/17 16:40:03 kk Exp $ --><sect1>User<p>The user class is an extension (a subclass) of the Sessionclass. It keeps a list of global variable names and provides aset of functions to load and save these variables from and to adatabase. The same restrictions as for session variables applyto user variables.Unlike session variables, user variables are not lost when theuser stops and restarts the browser or moves to a differentworkplace (the session id is then lost and consequently allsession variables are lost, since they are bound to the sessionid).User variables require that the user logs in, because theydepend on the availability of a User id to bind variables tothis id. Thus, User is dependent on Auth.The User class is an extension of the Session class. It has allinstance variables and instance methods of Session, only thatsome are implemented different. This documentation onlydescribes these differences.Note that Session and User can successfully share a single<tt/active_sessions/ table in a database due to thedifferent values in the <tt/name/ column.<sect2>Instance variables<p><table><tabular ca="">classname<colsep>Serialization helper: The name of this class.magic<colsep>Not meaningful for User.<rowsep>mode<colsep>Not meaningful for User.<rowsep>fallback_mode<colsep>Not meaningful for User.<rowsep>lifetime <colsep>Not meaningful for User; see authentication lifetime in Auth instead.<rowsep>gc_time<colsep>Functional, but probably not useful in User.<rowsep>gc_probability<colsep>Functional, but should be set to 0 in User.<rowsep>that_class<colsep>A classname. User uses this class to store and retrieve data.<rowsep>auto_init<colsep>Not meaningful for User.<rowsep>secure_auto_init<colsep>Not meaningful for User.<rowsep></tabular><caption>Accessible instance variables.</caption></table><table><tabular ca="">pt<colsep>Internal array of names of persistent variables.<rowsep>name<colsep>A tag (name) for the session type.<rowsep>id<colsep>Id of the current session.<rowsep>that<colsep>Container object instance.<rowsep></tabular><caption>Internal instance variables.</caption></table><sect2>Instance methods<p><sect3>Accessible instance methods<p><descrip><tag>register($varname)</tag><p>Works as expected.<tag>unregister($varname)</tag><p>Works as expected.<tag>delete()</tag><p>Works as expected. <tag>url($url)</tag><p>Not useful with User.<tag>purl($url)</tag><p>Not useful with User.<tag>self_url()</tag><p>Not useful with User.<tag>pself_url()</tag><p>Not useful with User.<tag>reimport_get_vars()</tag><p>Works as expected.<tag>reimport_post_vars()</tag><p>Works as expected.<tag>reimport_cookie_vars()</tag><p>Works as expected.</descrip><sect3>Internal instance methods<p><descrip><tag>get_id()</tag><p>This is only a stub implementation that depends on the user id provided by the page management functions. The page management functions will use <tt/$auth->auth["uid"]/, which is set up by <tt/Auth/. <tag>put_id()</tag><p>Empty. Not useful with User.<tag>serialize($prefix, &$str)</tag><p>Works as expected.<tag>freeze()</tag><p>Works as expected.<tag>thaw()</tag><p>Works as expected.<tag>gc()</tag><p>Works as expected. You do not want to use it, though.<tag>reimport_any_vars($arrayname)</tag><p>Works as expected.<tag>start()</tag><p>Initialization function, to be called after object instantiation. Calls get_id() to get the current session id, creates a database connection, then calls thaw() to load all session variables. <em/Note:/ gc() activation is commented out! Remove the comments if you really want gc with User variables.</descrip><p><sect2>Example<p>Use a subclass to provide the appropriate parameters to youruser variables. Usually your subclass looks like this:<tscreen><code>class My_User extends User { var $classname = "My_User"; ## Persistence support var $that_class = "CT_Sql";}</code></tscreen>Remember that you have to provide a <tt/DB_Sql/ subclass with theparameters needed to access your database.Use the page management functions (see above) to use yourUser subclass. The feature name for user variables is<tt/user/; provide the name of your User subclass as a parameterto the user feature:<tscreen><code> page_open(array("sess" => "My_Session", "auth" => "My_Auth", "user" => "My_User"));</code></tscreen>Use the <tt/register()/ instance method to register variables aspersistent. If <tt/$user/ is your user object, use<tscreen><code>$user->register("u");</code></tscreen>to make the global variable <tt/$u/ persistent. <tt/$u/ may be ascalar value, an array or an object with persistence supportslots.Do not use the instance methods <tt/freeze()/ and <tt/thaw()/directly, but use the page management functions instead.<em/Note:/ Using default authentication and user variables isgoing to be a problem, because currently <tt/User/ does not doany locking. This is, because the <tt/DB_Sql/ has currently noportable locking mechanism.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -