PRADOメモ
提供: Wikipokpok
目次 |
動作環境
http://localhost/prado-3.1.0.r2045/requirements/index.php
warningがあるけどよくわからないのでこのまま進みます。
インストール
適当なディレクトリに移動して解凍する。
$ unzip /path/to/prado-3.1.0.r2045.zip
- PRADO アプリケーション作成
$ php /path/to/prado/prado-3.1.0.r2045/framework/prado-cli.php -c . Command line tools for Prado 3.1.0. creating /path/to/prado/assets creating /path/to/prado/protected creating /path/to/prado/protected/runtime creating /path/to/prado/protected/pages creating /path/to/prado/index.php creating /path/to/prado/protected/application.xml creating /path/to/prado/protected/.htaccess creating /path/to/prado/protected/pages/Home.page
- 作成したPRADOアプリケーションにアクセス
http://localhost/prado/
認証と承認
モジュールを追加する。/protected/application.xml
<service id="page" class="TPageService">
<modules>
<module id="auth" class="System.Security.TAuthManager"
UserManager="users" LoginPage="UserLogin" />
<module id="users" class="System.Security.TUserManager"
PasswordMode="Clear">
<user name="demo" password="demo" />
<user name="admin" password="admin" />
</module>
</modules>
</service>
- /protected/pages/config.xml アクセス制限を記述する。
<?xml version="1.0" encoding="utf-8"?> <configuration> <authorization> <deny users="?" /> </authorization> </configuration>
- ユーザーの種類
*(アスタリスク) 全ユーザー @(アットマーク) 登録ユーザー ?(クエスチョンマーク) ゲストユーザー
- ログイン画面の作成
$ vi protected/pages/Login.php
class Login extends TPage
{
/**
* Validates whether the username and password are correct.
* This method responds to the TCustomValidator's OnServerValidate event.
* @param mixed event sender
* @param mixed event parameter
*/
public function validateUser($sender,$param)
{
$authManager=$this->Application->getModule('auth');
if(!$authManager->login($this->Username->Text,$this->Password->Text))
$param->IsValid=false; // tell the validator that validation fails
}
/**
* Redirects the user's browser to appropriate URL if login succeeds.
* This method responds to the login button's OnClick event.
* @param mixed event sender
* @param mixed event parameter
*/
public function loginButtonClicked($sender,$param)
{
if($this->Page->IsValid) // all validations succeed
{
// obtain the URL of the privileged page that the user wanted to visit originally
$url=$this->Application->getModule('auth')->ReturnUrl;
if(empty($url)) // the user accesses the login page directly
$url=$this->Service->DefaultPageUrl;
$this->Response->redirect($url);
}
}
}
?>
- $ vi protected/pages/Login.page
<html>
<head><title>ログイン</title></head>
<body>
<h1>ログイン</h1>
<com:TForm ID="Main">
<span>ユーザー名</span>
<com:TRequiredFieldValidator
ControlToValidate="Username"
ErrorMessage="Please provide your username."
Display="Dynamic" />
<br/>
<com:TTextBox ID="Username" />
<br/>
<span>パスワード</span>
<com:TCustomValidator
ControlToValidate="Password"
ErrorMessage="Your entered an invalid password."
Display="Dynamic"
OnServerValidate="validateUser" />
<br/>
<com:TTextBox ID="Password" TextMode="Password" />
<br/>
<com:TButton Text="Login" OnClick="loginButtonClicked" />
</com:TForm>
</body>
</html>
Blog Tutorial
sqlite3インストール
~$ sudo apt-get install sqlite3 libsqlite3-dev

