如何在一个级别的深层文件中访问对象?

时间:2014-03-30 10:23:54

标签: php wordpress require-once

在我的header.php文件中,我写道:

 <?php require_once('includes/session.php');?>

在我的admin_login.php文件中,我写道:

 get_header(); 
 global $session;
 $session->login($found_user);    

get_header()将包含header.php'session'类  <?php require_once('includes/session.php');?>

和admin_login.php由get_header()提供header.php。

那么为什么会话类在我的admin_login.php中不可用?它显示以下错误:

Call to a member function is_logged_in() on a non-object in 
D:\server\htdocs\wordpress\wp-content\themes\amrajegeachi.com\super_admin_home.php on line 9

admin_login.php中的所有代码:

<?php 
  /*
    Template Name: admin login form
  */
?>

<?php 
require_once('includes/user.php');
get_header(); // includes.session.php has been included by header.php

?> 
      <div id="super-admin-login">              
  <?php 
if(isset($_POST['login-btn']))
{
    if(!empty($_POST['user']) || !empty($_POST['password']))
      {
          $username=$_POST['user'];
          $password=$_POST['password']; 
          $found_user = User::authenticate($username,$password);
          if($found_user){
              global $session;
               $session->login($found_user);   
          }  
      }
}
?>
  <form name="input" action="#" method="post">
    <table>
      <tr><td> Username:</td><td><input type="text" name="user" /></td> </tr>
      <tr><td> Password:</td><td><input type="password" name="password" /></td> </tr>
      <tr><td> </td><td class="btn"> <input type="submit" name="login-btn" value="Login" /></td></tr>
    </table> 
</form>
      </div>       
   <?php  
    get_footer();
    ?>

1 个答案:

答案 0 :(得分:0)

我已修复此错误。我将getheader()更改为require_once(&#34; header.php&#34;);现在它工作正常