我尝试在另一个类中访问另一个类的方法,例如基于oops,但是我没有成功,我在这里描述了我的问题 我创建一个名称空间 如下面的目录 目录:Tets / test.php及其代码如:
<?php
namespace Test;
final class TestClient
{
public static function GetStoryById($fb_user_id)
{
$all_story=array();
$query="select * from story where fb_user_id='".$fb_user_id."' order by story_id desc";
$query_run= mysql_query($query);
echo mysql_error();
$num_rows= mysql_num_rows($query_run);
if($num_rows>0)
{
$fb_user_id=$data['fb_user_id'];
while($row= mysql_fetch_assoc($query_run))
{
$all_story['story_id']=$row['story_id'];
$all_story['fb_user_id']=$row['fb_user_id'];
$all_story['tagline']=$row['tagline'];
$all_story['experience']=$row['experience'];
$all_story['category_type']=$row['category_type'];
$all_story['lat']=$row['lat'];
$all_story['log']=$row['log'];
$all_story['datetime']=$row['datetime'];
$all_story['last_update_at'] =$row['last_update_at'];
}
}
if(!empty($all_story['story_id']))
{
$all['all_story']=$all_stories;
$all['statusmessage']="ok";
$all['statuscode']="1";
}
else{
$all['statusmessage']="there is no story found";
$all['statuscode']="2";
}
$response['response']= array_reverse($all);
$deatils=json_encode($response);
return $details;
}
}
I need to access its Function GetStoryById
in another php file which is like
--get.php
and code like
<?php
define('Tets-SDK-DIR', './Tets');
use Test\TestClient;
class facebook_details {
public function user_detail_with_story($data)
{
$query="select * from user where fb_user_id='".$data['fb_user_id']."'";
$query_run= mysql_query($query);
$num_rows= mysql_num_rows($query_run);
if($num_rows>0)
{
$row= mysql_fetch_assoc($query_run);
$status['user_details']=$row;
$fb_user_id= $data['fb_user_id'];
$status['all_details']=TestClient::GetStoryById($fb_user_id);
}
echo json_encode($status);
}
}
$facebook_details=new facebook_details();
if($_REQUEST['action']=='user_detail_with_story')
{
$facebook_details->user_detail_with_story($_REQUEST);
}
当我尝试通过提供action = user_detail_with_story&amp; user_id = 10来访问url时 我得了胎儿错误 致命错误:在第16行的......中找不到类'Test \ TestClient'
Pl z帮助我如何通过任何方法在另一个类中使用另一个类对象,所以我需要一次又一次地编写方法
我将等待回复
由于
答案 0 :(得分:1)
我解决了我的问题,只需在此行代码上方使用此代码include './Test/Test.php';
即可
或者在课前
$状态[&#39; all_details&#39;] = TestClient的:: GetStoryById($ fb_user_id);