Zend_AMFをまともに使ってみたときの話
Zend AMFを扱っているサイトは多いのですが、いまいち使い方がわかんない。というあなたへ
Zend AMFはZend Frameworkの一部なのですが単体でダウンロードもできるぐらい特別扱いされてます。
理由はAdobeからの支援を受けていることと、Flash Builder 4でプロジェクトにZend_AMFを内包できるところにあると。
Zend Framewokの元来のフレームワークとしての使いかたにのとってやる場合、Zend_toolのZFコマンド使ってディレクトなどを生成してやる方法が楽チンです。
ZendFrameworkで作る『イマドキ』のWebアプリケーション
準備ができたら、 amfコントローラーを用意します。
class IndexController extends Zend_Controller_Action { public function init() { /* Initialize action controller here */ } function indexAction() { } function addAction() { } function editAction() { } public function deleteAction() { } public function profileAction() { $this->_helper->layout->disableLayout(); Header("Content-disposition: attachment; filename=test.xml"); Header("Content-type: application/octet-stream; name=test.xml;"); } public function loginAction(){ $errors = array(); if ($this->getRequest()->isPost()){ $username = $this->getRequest()->getParam('username'); $password = $this->getRequest()->getParam('password'); $auth = Zend_Auth::getInstance(); $adapter = new GijirokuAuthAdapter($username,$password); $result = $auth->authenticate($adapter); if ($result->isValid()){ $this->_redirect('/index'); } else { $auth->clearIdentity(); $errors = $result->getMessages(); } } $this->view->assign('errors',$errors); } public function checkLogin(){ $auth = Zend_Auth::getInstance(); if (!$auth->hasIdentity()){ throw new Zend_Auth_Adapter_Exception('認証されていません。',Zend_Auth_Result::FAILURE_IDENTITY_NOT_FOUND); } else { $this->view->assign('username',$auth->getIdentity()); } } }