From: Boris Z. <bz...@2b...> - 2004-05-18 09:21:57
|
Hi, here are some basic hints, how to use the new Apache::Test environment. Very rough, but usefull. Apache::PageKit quickstart Learning Apache::PageKit in 10 minutes. Building the development environment Use Apache::Reload tar zxf Apache-PageKit-1.14.tar.gz cd Apache-PageKit-1.14 perl Makefile.PL make emacs ./t/conf/extra.last.conf at the top of the file there are three lines commented out. # PerlModule Apache::Reload # PerlInitHandler Apache::Reload # PerlSetVar ReloadAll On uncomment these lines. Save the file and install Apache::Reload if needed. first server start now start the testserver with ./t/TEST -start-httpd the steps so far are not needed, but it makes your development much more easy. Now Apache::Reload takes care of our changes on the fly. No more apache restarts ( almost ). stop the server ./t/TEST -stop-httpd reconfig If something needs to change, change it in ./t/conf/extra.last.conf.in. IE: if the output to your error_log is to verbose, add LogLevel warn to ./t/conf/extra.last.conf.in. Next let Apache use the new config with. ./t/TEST -conf more there are some more options to "./t/TEST" watch them ./t/TEST -help to start a server with some more clients use: ./t/TEST -start-httpd -maxclients=20 Looking for errors Start another xterm and cd to the directory Apache-PageKit-1.14 from above. cd Apache-Pagekit-1.14 tail -f ./t/logs/error_log Watch the error log for errors and other info. Some easy templates first Cd to the Apache-PageKit-1.14 directory. Start a editor: emacs eg/View/Default/first.tmpl and type: <html> <body> This is my first page! </body> </html> save that and try it http://localhost:8529/first Now put some PKIT_COMPONENTS ( SSI on steroids ) in. second emacs eg/View/Default/second.tmpl <PKIT_COMPONENT NAME="/top"> Second Page <PKIT_COMPONENT NAME="/bottom"> and the test! http://localhost:8529/second Modelcode third building a third template named third.tmpl. emacs eg/View/Default/third.tmpl <PKIT_COMPONENT NAME="/top"> <MODEL_VAR hi> <PKIT_COMPONENT NAME="/bottom"> save and try http://localhost:8529/third The page is empty, since 'hi' is unset. To add some code for it do: emacs eg/Model/MyPageKit/MyModel.pm sub third { my $model = shift; $model->output( hi => "Hi There" ); } C<$model> is our model object it can normaly everything you add to eg/Model/MyPageKit/Common.pm and http://pagekit.org/guide/ch02s02.html ( everything under PageKit API ). save and try again http://localhost:8529/third four emacs eg/View/Default/four.tmpl <PKIT_COMPONENT NAME="/top"> <MODEL_VAR hi>, there are <b><MODEL_VAR count/></b> entries in the table.<br> <MODEL_LOOP users> <MODEL_VAR login> <MODEL_VAR email><br> </MODEL_LOOP> <PKIT_COMPONENT NAME="/bottom"> emacs eg/Model/MyPageKit/MyModel.pm sub four { my $model = shift; my $dbh = $model->dbh; my $rows = $dbh->selectall_arrayref(q{ SELECT login, email FROM pkit_user ORDER BY login LIMIT 100 }, { Slice => {} } ); $model->output( hi => "Hi There", count => scalar(@$rows), users => $rows ); } save and try again http://localhost:8529/four. The last example queries our user database and output the first 100 users. Add some more. protect a page require a login To protect the last example page four edit the file eg/Config/Config.xml. We add a entry in the <PAGES> section. <PAGE id="four" require_login="yes"/> now if you visit the page four again you end on the loginpage, unless you are already logged in. If you do not have a login_page defined ( Config.xml/GLOBAL section ) you end on the default_page. The functions that validate your login are 'pkit_auth_credential' and 'pkit_auth_session_key' in eg/Model/MyPageKit/Common.pm. You can change the functions in any way you like. SEE ALSO Apache::PageKit, Apache::PageKit::FAQ, <http://pagekit.org/guide/index.html> -- Boris |