Quickstart
From JFramework Wiki
This document intends to be a 10 minute quickstart guide for a jFramework newbie. It aims to let the developer create a Hello World example with a few tweaks.
Contents |
Deployment
If you download jFramework via its official website, You'll most likely receive a tarball or a zipped package, namely jf***.tar.gz' where *** stands for version. You'll need to extract the tarball, which gives you a trunk folder. You can skip this step by exporting a live SVN trunk version from the repository:
$ svn export svn://jframework.info/jf/svn/trunk/
Which gives you the same trunk folder, but with slightly newer file versions (not recommended for stable developments). The next step is to configure jFramework, so open up trunk/app/config/application.php in any UTF-8 editor (with no BOM of course!) and read through it for customizing your application. The necessary changes to make are application name, version, title and database setup if you need one. If you don't need a database for your deployment, simply remove the line assigning database user:
reg("jf/db/default/user","root"); #comment this for no-DB jFramework
As you can see, there are multiple database setups for your default database, Which make it easier for you to work on a development and operational version of your application at the same time. After providing jFramework application configuration file with your database credentials, Make sure to create a database at your server with the same credentials. Also make sure to import required SQL data into newly created database (available at trunk/install/_db/adapter.sql where adapter is your desired database, e.g MySQL).
You're ready to go, upload your trunk folder to the web server, name it to whatever you want (e.g myjf) and point your browser to http://mywebserver/myjf/ . The jFramework initial page should pop up.
Development
Now it's time to replace jFramework's default homepage with your own Hello World application. We'll need to work with the following files:
- trunk/app/control/main.php
- trunk/app/view/default/main.php
Open these files in a PHP Editor, As you can see, a MainController class is defined in the control/main.php file derived from BaseControllerClass , Which is the default controller for your website. There's also a Start() function inside it, Clear its contents and write down just this single line of code:
$this->Present();
Now the second file, After you had it open, Clean it, Type in:
<h1>Hello jFramework World!</h1>
And done! save both files and refresh your browser. As you can see, Your hello world is visible but is stuck between the old header and footers. To customize header and footer, open these two files and edit them to your own accord:
- trunk/app/view/default/_template/head.php
- trunk/app/view/default/_template/foot.php
Note that you can't simply clean these two files, Since HTML header, body and etc. tags are enclosed in these two files, So the least they should have is :
head.php
<html> <head> </head> <body>
foot.php
</body> </html>
Furthur Development
Now lets get our hands a little dirty, create these two files:
- trunk/app/control/hello/world.php
- trunk/app/view/default/hello/world.php
In the second file, Which represents our (V)iew part of MVC pattern, just write down something like:
<?php if (isset($this->Name)) { ?>
Hello <?php echo $this->Name ?>, the new jFramework visitor!
<?php } else { ?>
<form>Enter your name: <input type='text' name='name' /> <input type='submit' /></form>
<?php } ?>
Now open up the (C)ontroller part of our MVC pattern, Which is the first file, And code:
class HelloWorldController extends BaseControllerClass
{
function Start()
{
if (isset($_GET['name']))
$this->Name=$_GET['name'];
return $this->Present();
}
}
And test your new application at http://mywebserver/myjf/hello/world !
The point here was that the url path http://mywebserver/myjf/folder1/folder2/folder3/file corresponds to a file at trunk/app/control/folder1/folder2/folder3/file.php and a classname of Folder1Folder2Folder3File (first capital letters) for the controller.
To learn more about jFramework, study its Libraries.