PunyApp
1.0.0
Punyapp는 외부 PHP 확장이 필요하지 않은 가벼운 MVC PHP 프레임 워크이며 CakePHP 프레임 워크를 기반으로합니다.
PHP 5.5.0 또는 최신이 필요합니다.
응용 프로그램 디렉토리 레이아웃 :
/application
/controllers -> App controllers
/models -> App models
/views -> App views
/libraries -> App libraries
/storage -> App storage
/settings -> Application settings
app-settings.php
app-scheme.php
/public -> public web
/css
/js
index.php
/punyapp -> PunyApp libraries
/vendors -> Vendors
index.php
class SampleController extends PunyApp_Controller {
public $ models = array ( ' sample ' );
/**
* GET /login
*/
public function getLogin ( $ params ) {
$ this -> view -> render ( ' sample/login ' );
}
/**
* POST /login
*/
public function postLogin ( $ params ) {
$ has = $ this -> sample -> hasUser ( $ params [ ' id ' ], $ params [ ' pass ' ]);
if ( $ has ) {
$ this -> session -> userid = $ params [ ' id ' ];
$ this -> redirect ( ' home ' );
}
// ...
}
/**
* Any /login
*/
public function anyLogin ( $ params ) {
// ...
}
/**
* Before /login
*/
public function beforeLogin ( $ params ) {
if (! empty ( $ this -> session -> userid )) {
$ this -> redirect ( ' home ' );
}
}
/**
* After /login
*/
public function afterLogin ( $ params ) {
// ...
}
/**
* GET /home
*/
public function getHome ( $ params ) {
if ( empty ( $ this -> session -> userid )) {
$ this -> redirect ( ' login ' );
}
$ this -> view -> user = $ this -> sample -> getUser ( $ this -> session -> userid );
$ this -> view -> render ( ' sample/home ' );
}
/**
* GET /register
*/
public function getRegister ( $ params ) {
$ this -> view -> render ( ' sample/register ' );
}
/**
* POST /register
*/
public function postRegister ( $ params ) {
if ( $ this -> validate ()) {
$ this -> sample -> addUser ( $ params [ ' id ' ], $ params [ ' email ' ], $ params [ ' pass ' ]);
$ this -> session -> userid = $ params [ ' id ' ];
$ this -> redirect ( ' home ' );
}
$ this -> view -> render ( ' sample/register ' );
}
}준비된 진술을 사용합니다.
class SampleModel extends PunyApp_Model {
public function addUser ( $ userid , $ email , $ pass ) {
$ sample = $ this -> newInstance ();
$ sample -> userid = $ userid ;
$ sample -> email = $ email ;
$ sample -> pass = sha1 ( $ pass );
return $ sample -> save ();
}
public function deleteUser ( $ userid ) {
return $ this -> delete (
array ( ' userid ' => ' ? ' ),
array ( $ userid )
);
}
public function getUser ( $ userid ) {
return $ this -> findOne (
array (
' fields ' => array ( ' id ' , ' userid ' , ' email ' ),
' where ' => array ( ' userid ' => ' ? ' )
),
array ( $ userid )
);
}
public function hasUser ( $ userid , $ pass ) {
return $ this -> has (
array (
' where ' => array (
' userid ' => ' :userid ' ,
' pass ' => ' :pass '
)
),
array (
' :userid ' => $ userid ,
' :pass ' => sha1 ( $ pass )
)
);
}
}
순수한 PHP 템플릿을 사용합니다.
템플릿 변수는 기본적으로 HTML 엔티티에 대해 탈출됩니다.
$ this -> view -> text = ' Hello! ' ;
$ this -> view -> render ( ' index ' );Views/Index.php
<html>
<body>
<h1>Sample</h1>
<?php echo $ text ; ?>
</body>
</html>응용 프로그램 이벤트를 처리하거나 자신을 정의하십시오.
// Handle the database error
$ this -> event -> on ( ' app-database-error ' , function ( $ app , $ error ) {
if ( $ app -> isDebug ()) {
// Show error message only in debug mode
echo $ error ;
}
});양식 유효성 검사 요청.
public $ validationRules = array (
' id ' => array (
' required ' => true ,
' rule ' => array ( ' regex ' , ' /^[a-z0-9]{1,10}$/i ' ),
' message ' => ' Only letters and integers, max 10 characters '
),
' email ' => array (
' required ' => true ,
' rule ' => array ( ' email ' ),
' message ' => ' Invalid email address '
),
' pass ' => array (
' required ' => true ,
' rule ' => array (
array ( ' minLength ' , 4 ),
array ( ' maxLength ' , 20 )
),
' message ' => ' Min 4 characters, max 20 characters '
)
);서버의 모든 디렉토리로 파일을 추출합니다.
설정 application/settings/app-settings.php .
$ settings = array (
/**
* System settings
*/
' system ' => array (
/**
* Timezone
*
* e.g., 'America/Chicago', 'Asia/Tokyo' etc.
*/
' timezone ' => '' ,
),
/**
* Database settings
*/
' database ' => array (
/**
* Database engine
*
* Available engines: "mysql", "pgsql", "sqlite" and "posql".
*/
' engine ' => '' ,
),
/**
* Session settings
*/
' session ' => array (
/**
* Session engine
*
* Available engines: "php", "file" and "database".
*/
' engine ' => '' ,
)
); application/settings/app-schema.php 에서 데이터베이스 스키마를 만들거나 스키마를 쓰십시오.
application/storage 아래 디렉토리 및 파일에서 쓸 수있는 것으로 설정됩니다.
첫 번째 파일 추출 된 디렉토리를 찾아보십시오.
/sample/ 에 샘플 로그인 양식이 있습니다.Punyapp는 MIT 라이센스에 따라 라이센스가 부여 된 오픈 소프트웨어입니다.