window/Sessions
directory. These files are used to define
session key names and the name is later imported into frame files which can be shared to routes. In most cases,
one session file is needed within the application. However, when certain situation arises for the need of a different session file, then the
session files comes into play. For example, a session file can help to separate an admin data from a user data if the admin data is stored
under a different session key. Consider the example below where we have three files:
<?php new Session('user', 'usercookie');
<?php new Session('admin', 'admincookie');
<?php
namespace spoova/mi/windows/Frames;
use Window;
use User;
session('usersession')
class UserFrame extends Window {
function __construct() {
vdump( User::config('SESSION_NAME') ); //session
}
}
<?php
namespace spoova/mi/windows/Frames;
use Window;
use User;
session('adminsession')
class AdminFrame extends Window {
function __construct() {
vdump( User::config("SESSION_NAME") ); //admin
}
}
window/Sessions/
directory. Within each session file in "1a"
and "2a"
above, we
defined two different session keys "user" and "admin" in which relative session data are expected
to be stored. Once the key is stored, we can then import the session files into any frame file
using the session()
function which was built to load session files into window files by
calling the session file name. In the example above, the Userframe
class will connect to the
UserSession
file while the class AdminFrame
will connect to the
AdminSession
file. By defining the session()
at the top of the class, it ensures that when we
call the session is always added and not overridden from any method. However, if we are sure that the super()
of window or in this case "frame" files will not be overridden, then we can declare the session within a the super()
method which is usually being called at the
start of any route. An example is shown below:
<?php
namespace spoova/mi/windows/Frames;
use Window;
use User;
class AdminFrame extends Window {
function __construct() {
vdump( User::config('SESSION_NAME') ); //admin
}
static function super() {
session('adminsession');
}
}
AdminFrame
file calls the AdminSession
file using the global super()
method. Once we declare the session keys, we can then
extends the session frame files to routes. The children route of the relative session frames will
only have access to their respective parent session keys. This makes it easier to deal with session
data and helps to distinguish between one session from another.