Getting Up and Running with the Swat Demo
Since Swat's 1.0 release, we've had a few people tell us getting started with Swat is too difficult. To help people get started, here is a quick tutorial on how to get the Swat Demo running on your own server.
To get the Swat Demo running you'll need the following:
Step 1: Installing the PHP
Using PEAR
If you are using PEAR to manage your PHP packages you can get PEAR::Date from the main PEAR channel (pear.php.net) and Swat from the silverorange's PEAR channel (pear.silverorange.com).
The main PEAR channel is installed by default when you are using PEAR. You can install PEAR::Date using:
pear install Date
To add the silverorange PEAR channel to your PEAR install, use:
pear channel-discover pear.silverorange.com
You can then install the Swat package by using:
pear install so/Swat
Swat will install the Swat demo in <pear-dir>/data/Swat/demo
Using Release Archives:
Download the latest Swat release. Download PEAR::Date from the PEAR::Date download page.
Extract the entire Swat archive into <install-dir>. Extract PEAR::Date into a path that is in your PHP's include_path. The Swat demo will be in <install-dir>/demo
Step 2: Installing YUI
Most of Swat's UI objects using JavaScript make use of the Yahoo User Interface Library (YUI) to abstract cross-browser event-handling, DOM manipulation and CSS positioning. The latest release of the Yahoo User Interface Library (YUI) is available for download at the YUI download page (Sourceforge).
After downloading the latest YUI release, open the archive and extract everything in the build directory into demo/www/packages/yui. You'll have to perform this step for websites you create using Swat as well.
We don't distribute YUI with Swat because:
- we don't want to unintentionally fork YUI,
- we don't want to deal with including BSD code in our LGPL code,
- we want to encourage users to use the latest available version of YUI.
Step 3: Configuring your Web Server
Configure your web server to use allow browsing demo/www
Make sure the directory above Swat is in PHP's include_path and you should be all set.
Comments
Jon - February 14, 2007 2:06 PM
Followed you steps. Doesnt seem like the zip structure is right. I had to move the Swat folder in the root directory of the zip, into the demo/www folder. I am also experiencing some bugs on the SwatDetails view part of the demo.
Mike Gauthier - February 16, 2007 3:11 PM
Hi Jon,
The problem you're probably experiencing with having to move the Swat directory into demo/www is related to your PHP include path. Ideally, you should set your include path to include the root directory of the zip archive using the PHP set_include_path()/get_include_path() functions.
Can you let us know what bugs you are experiencing with the DetailsView demo?
Shawn - February 16, 2007 3:26 PM
When trying to run the demo I get this
<pre style="overflow: auto; width: 500px;">
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<?=$html_head_entries?>
<style type="text/css" media="all">@import "styles/demo.css";</style>
<title><?=$title?></title>
<link rel="icon" href="favicon.ico" type="image/x-icon" />
</head>
<body>
<?=$ui?>
</body>
</html>
</pre>
[edit] cleaned pasted XHTML output.
Mike Gauthier - February 16, 2007 5:57 PM
Shawn,
Either your PHP installation has the
short_open_tagsdirective turned off, or Apache is not set up to handle PHP files. Theshort_open_tagsdirective is on by default in PHP so we didn't think using short open tags in our template would be a problem. In a future release, we'll update the template to not use short open tags. In the meantime, you can change all occurrences of:<pre>
<?=$variable?>
</pre>
to
<pre>
<?php echo $variable; ?>
</pre>
Jon - February 17, 2007 3:08 PM
Hey Shawn,
Here is what I get when I try the DetailsView part of the demo:
<pre style="overflow: auto; width: 500px; height: 250px;">
Message:
moneyFormat() method is not available on this operating system. See http://php.net/manual/en/function.money-format.php for details.
Created in file C:\Program Files\xampp\htdocs\swat\demo\www\Swat\SwatString.php on line 691.
Stack Trace:
17.In file C:\Program Files\xampp\htdocs\swat\demo\www\Swat\SwatMoneyCellRenderer.php line 83.
Method: SwatString::moneyFormat(0.5, 'en_CA', , <null>)
16.In file C:\Program Files\xampp\htdocs\swat\demo\www\Swat\SwatDetailsViewField.php line 217.
Method: SwatMoneyCellRenderer->render()
15.In file C:\Program Files\xampp\htdocs\swat\demo\www\Swat\SwatDetailsViewField.php line 155.
Method: SwatDetailsViewField->displayRenderers(<FruitObject object>)
14.In file C:\Program Files\xampp\htdocs\swat\demo\www\Swat\SwatDetailsViewField.php line 112.
Method: SwatDetailsViewField->displayValue(<FruitObject object>)
13.In file C:\Program Files\xampp\htdocs\swat\demo\www\Swat\SwatDetailsView.php line 242.
Method: SwatDetailsViewField->display(<FruitObject object>, 1)
12.In file C:\Program Files\xampp\htdocs\swat\demo\www\Swat\SwatDetailsView.php line 159.
Method: SwatDetailsView->displayContent()
11.In file C:\Program Files\xampp\htdocs\swat\demo\www\Swat\SwatContainer.php line 436.
Method: SwatDetailsView->display()
10.In file C:\Program Files\xampp\htdocs\swat\demo\www\Swat\SwatForm.php line 216.
Method: SwatContainer->displayChildren()
9.In file C:\Program Files\xampp\htdocs\swat\demo\www\Swat\SwatContainer.php line 436.
Method: SwatForm->display()
8.In file C:\Program Files\xampp\htdocs\swat\demo\www\Swat\SwatFrame.php line 118.
Method: SwatContainer->displayChildren()
7.In file C:\Program Files\xampp\htdocs\swat\demo\www\Swat\SwatContainer.php line 436.
Method: SwatFrame->display()
6.In file C:\Program Files\xampp\htdocs\swat\demo\www\Swat\SwatDisplayableContainer.php line 31.
Method: SwatContainer->displayChildren()
5.In file C:\Program Files\xampp\htdocs\swat\demo\www\Swat\SwatContainer.php line 436.
Method: SwatDisplayableContainer->display()
4.In file C:\Program Files\xampp\htdocs\swat\demo\www\Swat\SwatContainer.php line 421.
Method: SwatContainer->displayChildren()
3.In file C:\Program Files\xampp\htdocs\swat\demo\www\Swat\SwatUI.php line 267.
Method: SwatContainer->display()
2.In file C:\Program Files\xampp\htdocs\swat\demo\include\DemoApplication.php line 408.
Method: SwatUI->display()
1.In file C:\Program Files\xampp\htdocs\swat\demo\include\DemoApplication.php line 81.
Method: DemoApplication->buildLayout()
0.In file C:\Program Files\xampp\htdocs\swat\demo\www\index.php line 19.
Method: DemoApplication->run()
</pre>
Sorry I didn't post it before. I appreciate your help with this, I am really interested in using Swat in some upcoming web developments.
-Jon
Mike Gauthier - February 18, 2007 6:40 PM
Hi Jon,
Are you using Swat on Windows? If this is the case, the message field of the exception accurately describes what is happening. PHP on Windows does not have a money_format() function.
The SwatDetailsView demo uses SwatMoneyCellRenderer which in turn uses SwatString::moneyFormat() which in turn uses PHP's money_format() function.
Working around this in the DetailsView demo can be done by replacing SwatMoneyCellRenderer with SwatNumericCellRenderer in the XML and then removing the currency specific properties in the XML.
If you need SwatString::moneyFormat() to work on Windows, we'd gladly accept a patch that emulates PHP's money_format() function on Windows.
Feel free to ask further questions here or on the swat-devel mailing list. The mailing list is read more frequently by more Swat developers.
johnrembo - January 31, 2008 12:00 PM
dooh!
it took me for a while to set-up swat's demo on windows box.
several notes to make it less paintfull:
a) start from putting
ini_set('display_errors',1);
error_reporting(E_ALL);
at the top of "c:/root/Swat/Swat-1.2.35/demo/www/index.php" to make sure you have debug messages visible.
b) php_gettext.dll - as far as I am not using this at all -I found it nearly impossible to find for php5. After long hour of digging I had to install WAMP (www.wampserver.com) and voila - under /wamp/bin/php/ext there was working php_gettext.dll
c) as it was already mentioned above - all of the includes fails, so place the following line at demo/www/index.php
set_include_path("c:/root/Swat/Swat-1.2.35;c:/root/Swat/Swat-1.2.35/Date/Date-1.4.7");
d) alternatively, create a folder named "packages" under c:/root and extract yahoo yui there.
e) create folder "swat" in c:/root/packages and put "styles" folder from c:/root/Swat/Swat-1.2.35/www/ there
jonrembo - February 1, 2008 9:12 AM
a little correction:
ignore prievious "d)"
d) - put the contents of yui/build to c:/root/Swat/Swat-1.2.35/demo/www/packages/yui
Johnston - July 21, 2009 12:34 PM
Hey, thank you for this timely tutorial. I was just about to give up on SWAT, not being able to understand it. But this tutorial explains it very well, and to be honest, SWAt seems quite simple now.
Regards, Johnston from rocky point auto insurance