自从我接触到PHP之后已经有一段时间了,所以我正试着为我的项目创建一个全局函数文件。最近一直专注于Javascript / AngularJS。
到目前为止,我有两个文件。我的globals.php
文件和我的api.php
文件。
globals.php:
class Globals
{
public function guid()
{
return "testing";
}
}
api.php:
include 'globals.php';
$globals = new Globals();
echo $globals->guid();
显然,上面的错误是错误的,因为我很可能错误地定义了我的课程。
如何在globals.php
文件中使用api.php
文件功能?
答案 0 :(得分:4)
假设你在一个文件名区分大小写的linux盒子上工作,你应该使用
<asp:LinkButton ID="uxLogout" runat="server" CausesValidation="false" Text="Log Out" OnClick="uxLogout_Click" />
除了这句话,代码正在运行。
还要确保在两个文件的开头都有php标记protected void uxLogout_Click(object sender, EventArgs e)
{
try
{
if (_cook != null) _cook.Logout();
}
catch (Exception ex) { Common.LogError("List", "uxLogout_Click", ex); }
Response.Redirect("~/Account/Login.aspx");
}
private Cookie _cook;
public bool Logout()
{
_cookie.RemoveAll();
_cookie.Abandon();
return true;
}
,最后是include 'Globals.php';
。
测试你包含
的路径<?php
答案 1 :(得分:0)
这取决于您存储类文件的位置,在本例中为Globals
。 includes_path
值通常是预定义的,但您可能需要在运行时将其设置为指向文件所在的位置。
set_include_path( $_SERVER['DOCUMENT_ROOT' ).'/includes';
/* Assuming you store the file in that location */
include 'Globals.php';