SETTING UP A SIMPLE WEBSITE --------------------------- Valid for Version: 0.2 Last Revised: 2004-06-30 Contents -------- 1. Get sample website 2. Install `kickstarter.php' 3. Make `cache' and `compiled' dir writable 4. Add pages to `pages.xml' 5. Add menu items to `menus.xml' 6. Browse 7. Playing with templates 8. Playing with contents 9. Basic execution flow 10. Further information 1. Get sample website --------------------- Get the mwlib-m.m-sample-website.tar.gz tarball on my homepage ( http://studer.tv ). % cd /path/to/your/webroot % cp /path/to/downloaded/mwlib-m.m-sample-website.tar.gz . % tar xzf mwlib-m.m-sample-website.tar.gz You should now have a very basic website. Use % ls and % cd folder to explore the folder structure. 2. Install `kickstarter.php' ---------------------------- The `kickstarter.php' file is the gateway file to your mwlib web pages. Every request of a http client is handled by `kickstarter.php'. Open `kickstarter.php' with you favourite text editor and look at the php code. Basically it's doing the following: - including mwlib - creating the framework - opening and executing the main template - shutting down the framework If every request is handled by 'kickstarter.php', how does it now which page to show? There are two possibilities to tell 'kickstarter.php' which page to show. Case 1: Using request rewrite techniques (mod_rewrite) ------- This is the preferred way to tell kickstarter.php which page to load as it does not clutter your website's directory with 'unnecessary' files. Configure your HTTP server in such a way that it rewrites each request to load `kickstarter.php' and pass the unique page_id by a GET-Parameter. Example excerpt for `.htaccess' or `httpd.conf' file for Apache: RewriteEngine On RewriteRule ^(.*)\.page$ kickstarter.php?page_id=$1 [L,QSA] Case 2: Using 'shadow PHP files' ------- This possibility does not require any HTTP server configuration. But it requires one small PHP file for each web page browsable by a HTTP client. This file only specifies the page_id and then includes the kickstarter.php. Example file somepage.php: 3. Make `cache' and `compiled' dir writable ------------------------------------------- mwlib caches some information inside the mwlocal/cache directory. Compiled templates are stored inside mwlocal/compiled. Thus, those two directories must be writable by the webserver user (normally `apache'). Type the following commands to make them writable (make sure the working directory is where you've installed the sample website): % chmod a+w mwlocal/cache mwlocal/compiled TODO: check, whether this is a security risk. I think, it is :-/ 4. Add pages to `pages.xml' --------------------------- Every page that can be accessed by a user must be listed in the `pages.xml' file. You also specify the standard template and templates for certain pages in there. Pages may be associated with menu entries if you're using the menu module. Note that the framework expects the `pages.xml' file to be on top level of a site. Open the file with the file with your favourite text editor and read the xml comments. 5. Add menu items to `menus.xml' -------------------------------- The `menus.xml' holds the structure for the menu module that displays navigation menus for every page. Every menu entry has a unique ID which the page defined in `pages.xml' refers to. The menu module expects the `menus.xml' file to be on top level of the site. Open the file with the file with your favourite text editor and read the xml comments. 6. Browse --------- Point your browser to the server where you've set up the sample website. Check if everything works as expected. If you see a "404 - Page Not Found" message, ensure that all requests are re-pointed (either by "shadow" php files or by mod_rewrite) to the `kickstarter.php' file (point 2). If there are error messages at the bottom of the page telling you that something could not have been saved, check point 3 again and make sure those directories are writable by the web server process. If you see error messages about `pages.xml' or `menus.xml', make sure they are valid xml. Check for proper tag nesting and special chars. 7. Playing with templates ------------------------- Open the `pages.xml' file again and look at the first tag. The attribute `template' defines the default template for all pages. Now change the attribute value from `tmpl_default.html' to `tmpl_alternative.html' and save. The template may be overwritten on a per-page basis (look at the entry of `about', for example). Point your web browser (which is certainly a mozilla derivate) to the homepage again. Everything changed! Nice, isn't it? The design is completely different without having written one single line of php code. If you think of it, that's the purpose of templates. ;) But it's often not as clean realized as in mwlib. *cough* Open the `tmpl_default.html' and the `tmpl_alternative.html' files, look at them and play a little bit. 8. Playing with contents ------------------------ You've certainly noticed all those `cnt_xxx.html' files inside the root directory of your website. Every one of them holds the content for one specific page specified in `pages.xml'. The naming scheme is quite obvious: "cnt_{page_id}.html" Let's open one of them with your favourite text editor. You'll see that they contain a full html page including , and tags. This is due to easier editing with WYSIWYG HTML editors. At the end, only parts of the source code inside those content files are parsed into the main template. Basically it's the and the <body> of the page. All content files are regarded as templates and thus compiled (if necessary) and executed at runtime! You can verify that by opening `cnt_about.html' that uses some modules to output dynamic data. 9. Basic execution flow ----------------------- So now you've seen all fundamental parts of the mwlib. But how are the pages generated? 1. Request from browser to webserver 2. Webserver executes `kickstarter.php' 3. `kickstarter.php' starts the framework 4. The framework decides on the basis of page_id and `pages.xml' which main template is required and executes it. 5. The main template executes the menu and content modules 6. The menu module loads `menus.xml' and outputs the menus to the main template. 7. The content module reads the right content file and executes it as a template. 8. The content module takes the output of the content file and passes the <title> and <body> parts to the main template. 9. The main template displays menus and contents. 10. The output is sent through the web server to the browser (which certainly is a mozilla derivate) 11. The execution finishes, the framework is shut down. 10. Further information ----------------------- Now you now the very basics of mwlib. To get the mwlib master's degree, I suggest doing the following: - Look at mwlocal/config.php (framework configuration) - Look at mwlocal/config.{module}.php (configuration file for module {module}) - Read the documentations about: * Basic concepts of mwlib * Templates * Modules * Caching Mechanisms (yummi, yummi, makes your websites fast as lightning!)