首先,你不能傳遞$的loggedIn變量到第二片斷,爲此常與後或會話變量。
其次,是檢查一個簡單的方法,這些都是直出Bob的指南:
There are various methods. One easy method is to use this code:
if ($modx->user->get('username') == '(anonymous)') {
/* user is not logged in */
}
Here is the official method for seeing if the user is logged in
to the current context:
if ($modx->user->hasSessionContext($modx->context->get('key'))) {
/* user is logged in */
}
If you know the name of the current context (e.g., web),
you can use this method. The name of the context is required:
if $modx->user->isAuthenticated('web') {
/* user is logged in to web context */
}
也就是說,如果你需要推出自己的身份驗證的某些原因。 〜否則,登錄/註冊額外將爲你做這一切。
* UPDATE ***從一個片段 兩個變量傳遞到另一個在相同的資源,你可以設置/獲取佔位符:
<?php
// snippet one
$modx->setPlaceholder('output','Place holder set!');
<?php
// snippet two
$myvar = $modx->getPlaceholder('output');
echo 'this is the value of "output": '.$myvar;
你可以只檢查'isset($ _ SESSION [ 'user_id']' – OptimusCrime