PHP 자동 으로 불 러 오 는 간단 한 구현(추천)
파일 구조:
|--Api
|--Account.php
|--User.php
|--Service
|--Login.php
|--User.php
|--Application.php
Application.php
<?php
use Api\User;
use Service\User as User2;
class Application{
public static function main(){
self::registe();
new User();
new User2();
}
public static function registe(){
spl_autoload_register("Application::loadClass");
}
public static function loadClass($class){
$class=str_replace('\\', '/', $class);
$class="./".$class.".php";
require_once $class;
}
}
Application::main();
Api\User.php
<?php
namespace Api;
use Service\Login;
class User{
public function __construct(){
echo "User <br/>";
new Login();
new Account();
}
}
Api\Account.php
<?php
namespace Api;
class Account{
public function __construct(){
echo "Account <br/>";
}
}
Service\Login.php
<?php
namespace Service;
class Login{
public function __construct(){
echo "Login <br/>";
}
}
Service\User.php
<?php
namespace Service;
class User{
public function __construct(){
echo "Service User <br/>";
}
}
결과:이상 의 PHP 가 자동 으로 불 러 오 는 간단 한 실현(추천)은 바로 편집장 이 여러분 에 게 공유 하 는 모든 내용 입 니 다.여러분 에 게 참고 가 되 고 저희 도 많이 응원 해 주시 기 바 랍 니 다.
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Laravel - 변환된 유효성 검사 규칙으로 API 요청 제공동적 콘텐츠를 위해 API를 통해 Laravel CMS에 연결하는 모바일 앱(또는 웹사이트) 구축을 고려하십시오. 이제 앱은 CMS에서 번역된 콘텐츠를 받을 것으로 예상되는 다국어 앱이 될 수 있습니다. 일반적으로 ...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.