라이브러리
[PHP] Yaf_Request_Simple::getPost - getPost 목적
Yaf_Request_Simple::getPost
Yaf_Request_Simple은 PHP의 Yaf 프레임워크에서 사용되는 요청 객체입니다. Yaf_Request_Simple::getPost 메소드는 POST 요청의 값을 가져올 때 사용됩니다.
# 사용법
Yaf_Request_Simple::getPost 메소드는 POST 요청의 값을 가져올 때 사용됩니다. 이 메소드는 요청 객체의 post 변수에 접근하여 값을 반환합니다.
# 예제
#hostingforum.kr
php
// index.php
<?php
require_once 'Yaf.php';
$app = new Yaf_Application('application.ini');
$app->bootstrap();
// 요청 객체 가져오기
$request = $app->getRequest();
// POST 요청의 값을 가져오기
$name = $request->getPost('name');
$age = $request->getPost('age');
// 값이 없을 경우 기본값을 설정
$name = $name ? $name : '이름';
$age = $age ? $age : 0;
// 출력
echo "이름 : $name
";
echo "나이 : $age
";
위 예제에서, `index.php` 파일에서 Yaf 프레임워크를 사용하여 요청 객체를 가져옵니다. 그 후, `getPost` 메소드를 사용하여 POST 요청의 `name`과 `age` 값을 가져옵니다. 만약 값이 없을 경우 기본값을 설정합니다.
# application.ini
Yaf 프레임워크의 설정 파일인 `application.ini` 파일을 생성하여 요청을 처리하도록 설정합니다.
#hostingforum.kr
ini
[application]
appdir = APPLICATION_PATH "/application"
module.path = APPLICATION_PATH "/modules"
resource.db.adapter = "PDO_MYSQL"
resource.db.params.host = "localhost"
resource.db.params.dbname = "test"
resource.db.params.username = "root"
resource.db.params.password = ""
[production]
resources.frontController.controllerDirectory = APPLICATION_PATH "/controllers"
resources.frontController.actionSuffix = "Action"
resources.frontController.defaultModule = "index"
resources.layout.layoutPath = APPLICATION_PATH "/layouts"
[production : :modules]
resources.frontController.moduleDirectory = APPLICATION_PATH "/modules"
; 요청을 처리할 모듈 설정
modules.index = "Index"
위 예제에서, `application.ini` 파일에서 요청을 처리할 모듈을 설정합니다.
# 모듈 생성
Yaf 프레임워크에서 요청을 처리할 모듈을 생성합니다.
#hostingforum.kr
php
// Index.php
<?php
class IndexController extends Yaf_Controller_Abstract {
public function indexAction() {
// 요청 객체 가져오기
$request = $this->getRequest();
// POST 요청의 값을 가져오기
$name = $request->getPost('name');
$age = $request->getPost('age');
// 값이 없을 경우 기본값을 설정
$name = $name ? $name : '이름';
$age = $age ? $age : 0;
// 출력
echo "이름 : $name
";
echo "나이 : $age
";
}
}
위 예제에서, `Index.php` 파일에서 요청을 처리할 모듈을 생성합니다.
# 요청 처리
Yaf 프레임워크에서 요청을 처리합니다.
#hostingforum.kr
bash
# 요청을 처리할 URL
http://localhost/index.php/index/index
# POST 요청의 값
name=홍길동
age=30
위 예제에서, Yaf 프레임워크에서 요청을 처리합니다. 요청을 처리할 URL을 입력하고, POST 요청의 값을 입력합니다.
# 결과
요청을 처리한 결과를 출력합니다.
#hostingforum.kr
이름 : 홍길동
나이 : 30
위 예제에서, 요청을 처리한 결과를 출력합니다. 요청을 처리한 결과는 요청을 처리한 모듈의 `indexAction` 메소드에서 출력한 값입니다.
-
- 나우호스팅 @pcs8404
-
호스팅포럼 화이팅!
댓글목록
등록된 댓글이 없습니다.