Author Topic: New Kid on the Block  (Read 1611 times)

Offline AcidicOne

  • Level 16
  • *
  • Posts: 147
  • Reputation: +0/-0
    • View Profile
New Kid on the Block
« on: December 28, 2008, 01:54:53 PM »
I first off would like to say Thanks to alot of you. I have been browsing the site the last couple days before registering browsing the forums, checking out the guides etc. And glad to see alot of the more experianced members on the forums are not the "RTFM" manual types.(although some people do deserve it,seriously google stuff sometimes,it does wonders)

That being Said, I have well as of late have been tossing around creating a browser mmorpg of sorts. I will be the first to say i have little programming experience, only relating to VB. Having picked up enough source code from source forge, and seeing all the helpful posters on the forums, am sure the idea which is now currently only alive on paper shall soon emerge :)


I have followed the tutorials and managed to reproduce the login/register page and get them working with sql. I have xmapp installed localy. Now that part I have a question on is the smart template. I've gone through alot of various  code from different games I have found on the web, and was curious as to the strengths and weakness's using smart instead of just a CSS file like I have seen some of the various games use. Seeing i have a basic idea of exactly what it is I want the game to do, and how it will all will be played out. I was looking to start setting up the basic framework without the game aspects involved aka login,registration,index,profile main game page,forums etc.
People Like You, Are the Reason People Like Me Need Medication

Offline Hypemaster

  • Level 16
  • *
  • Posts: 145
  • Reputation: +3/-0
    • View Profile
    • FusionBroz.com
Re: New Kid on the Block
« Reply #1 on: December 28, 2008, 02:20:06 PM »
Welcome!
What i can tell you about my experience with smarty is that its good if you want to make different templates for your game/website. I dont use it for my latests project because it makes my code only bigger and doesent add any more functionality's for me.  I just use my own template system wich is smaller and just have all functionality's i need. At the end its just about personal preference i think.

Offline Barrikor

  • Level 21
  • *
  • Posts: 248
  • Reputation: +3/-0
    • View Profile
Re: New Kid on the Block
« Reply #2 on: December 28, 2008, 03:21:34 PM »
I've never done a website with Smarty, what I do is just write up a CSS file and add a couple server-side includes for the banner, navigation bar, page text, etc.

What languages are you using for your framework?

Also what version of VB are you coming from? I love using VB6 but it's a bit lacking on OO. VB.NET is a bit annoying to look at, but I use it from time to time.
Projects: Pith Framework (at 0.5), CactusGUI (at 0.3)

Offline AcidicOne

  • Level 16
  • *
  • Posts: 147
  • Reputation: +0/-0
    • View Profile
Re: New Kid on the Block
« Reply #3 on: December 28, 2008, 03:42:24 PM »
Actually started in vb3, did vb6 for quite some time then finally grew up so to speak and quit writing programs for Aol and yahoo *Whistles*, but yeah i was debating doing CSS because i have no immediate plans to change the template for some time. I prefer functionality over appereance. And am assuming by framework you mean php,with ofcourse a mysql backend.
People Like You, Are the Reason People Like Me Need Medication

Offline Zeggy

  • Global Moderator
  • Level 35
  • *****
  • Posts: 1,187
  • Reputation: +13/-4
    • View Profile
Re: New Kid on the Block
« Reply #4 on: December 28, 2008, 03:45:52 PM »
For your first time, I'd suggest going without smarty, and just using includes.

Otherwise you'd need to take the time to learn smarty and implement it in your site. For every page (and even every different 'view' of a page) you'd need to create a separate template file, as well as the backend code.

You can do some pretty cool things easily in smarty though, but I just find that there's a little bit more work involved when it's not necessary.

Quote
I prefer functionality over appereance.
Well, smarty can enable some pretty nifty functionality... like letting users choose which template they want to play your game in. Or multiple languages. You could do this without smarty but you'd need to code your own template engine anyways.

Smarty doesn't actually have anything to do with appearance. You could have a horrible-looking site using smarty, and a sexy site that doesn't :P

Offline codestryke

  • Administrator
  • Level 33
  • *****
  • Posts: 589
  • Reputation: +22/-0
    • View Profile
    • eXtremeCast Games
Re: New Kid on the Block
« Reply #5 on: December 28, 2008, 04:29:13 PM »
This is where Zeggy and I disagree. I say start using Smarty right away and get use to setting it up and coding with it. The simple reason being Smarty forces good coding standards. I too have an extensive VB background so I can relate this easier.

Good coding standards with VB was never put code into the form, the form functions were only suppose to be used for making the controls work. The bulk of the logic for the app is suppose to be in modules, then of course storage goes to the database. Early Three Tier development Presentation, Logic, Storage.

Smarty with PHP is your form / presentation layer, PHP for logic and finally mySQL for storage. I see a LOT of code out there that has the presentation and php mixed together and that in the long run makes things difficult to debug when it comes to tweaking the layout in different browsers. How many here have had to dig deep into code because they forgot to close a td or tr tag it it though the layout off in either IE or FF? Now with heavy CSS and div usage it's even worse, god help you trying to look for that unclosed div tag in a myriad echo statements mixed with PHP logic.

Course everything is conditional. If I had small web site I wouldn't use smarty, to much overhead, but for something like a game where you are talking at least 20 pages or more of presentation then I think using Smarty is the way to go.
Creating online addictions, one game at a time:

Offline AcidicOne

  • Level 16
  • *
  • Posts: 147
  • Reputation: +0/-0
    • View Profile
Re: New Kid on the Block
« Reply #6 on: December 28, 2008, 05:28:19 PM »
I can see both points of few there, and  yes when i was learning VB the guy who taught me , well lets just say he was quite forthcoming on the yelling if i had more code on my form then i needed.

And There is of course nothing wrong with making someone learning proper coding standards (unless of course your sloppy on purpose for job security :P ) So i suppose I will give smarty a try, but have hit a small bump, am having trouble setting it up with my xmapp.The windows documentation seems to be scarce at best.


So here is the documentation i found for installing smarty in windows
Installing Smarty in Windows
http://news.php.net/php.smarty.dev/2703

This document assumes that your webserver and php5 is running.

Download Smarty - http://smarty.php.net

Installation - Windows, IIS/Apache, PHP5
Extract files, rename Smarty.x.x.x to smarty (suggest OUTSIDE of your www root!)
Example: d:\smarty
Run phpinfo.php to find out your php.ini location
Edit php.ini's include_path and add the location of the libs folder.
example: include_path = ".;d:\smarty\libs"
Restart IIS/Apache
Setup these two folders INSIDE your www root:
(wwwroot)/smarty/templates  (this is where your templates will go)
(wwwroot)/smarty/configs

Setup these two folders OUTSIDE of your www root:
d:/smarty/templates_c
d:/smarty/cache

Setup security settings for the webserver to write to these four folders

In (wwwroot) create index.php and in (wwwroot)/smarty/templates/index.tpl with the following code:

index.php:
<?php

// load Smarty library
require('Smarty.class.php');

$smarty = new Smarty;

$smarty->template_dir = 'd:/inetpub/wwwroot/smarty/templates';
$smarty->config_dir = ' d:/inetpub/wwwroot/smarty/config';
$smarty->cache_dir = 'd:/smarty/smarty_cache';
$smarty->compile_dir = 'd:/smarty/smarty_templates_c';

$smarty->assign('name','fish boy!');

$smarty->display('index.tpl');
?>

index.tpl
<html>
<body>
Hello, {$name}!
</body>
</html>

Now open index.php in your web browser (requested from your webserver)

http://webserver/index.php

You can work this out to a referenced script/class:
smarty_connect.php:
<?php

// load Smarty library
require('Smarty.class.php');

class smarty_connect extends Smarty
{
   function smarty_connect()
   {
        // Class Constructor.
        // These automatically get set with each new instance.

      $this->Smarty();

      $this->template_dir = ' d:/inetpub/wwwroot/smarty/templates';
      $this->config_dir = ' d:/inetpub/wwwroot/smarty/config';
      $this->compile_dir = 'd:/smarty/templates_c';
      $this->cache_dir = 'd:/smarty/cache';

      $this->assign('app_name', 'Intranet');
   }
}
?>

index.php:
<?php

require('smarty_connect.php');

$smarty = new smarty_connect;

$smarty->assign('name','Ned');

$smarty->display('index.tpl');
?>

index.tpl:
<html>
<body>
 Hello, {$name}!
</body>
</html>


If you are getting an error that Smarty.class.php isn't found chances are that your include_path isn't correct or you didn't edit the one that the webserver is using, check your phpinfo.php!

Now i have edited the php.ini for the includes,Where i catch the bump is the index.tpl and index.php
This write up is not exactly beginner friendly.

Now what i get from this is I am to create index.php in my htdocs with no code in the file itself
Then creating index.tpl with the code suggested in it

now it says the location is in templates,when it only had me create a template_c folder, so should I have both folders, or is only template_c needed.And for the second dilemma


$smarty->template_dir = 'd:/inetpub/wwwroot/smarty/templates';
$smarty->config_dir = ' d:/inetpub/wwwroot/smarty/config';
$smarty->cache_dir = 'd:/smarty/smarty_cache';
$smarty->compile_dir = 'd:/smarty/smarty_templates_c';

am assuming I am to change this to my settings which would be

$smarty->template_dir = 'c:/C:/xampp/htdocs/smarty/templates';
$smarty->config_dir = ' c:/C:/xampp/htdocs/smarty/config';
$smarty->cache_dir = 'c:/smarty/smarty_cache';
$smarty->compile_dir = 'c:/smarty/smarty_templates_c';
« Last Edit: December 28, 2008, 06:40:37 PM by AcidicOne »
People Like You, Are the Reason People Like Me Need Medication

Offline codestryke

  • Administrator
  • Level 33
  • *****
  • Posts: 589
  • Reputation: +22/-0
    • View Profile
    • eXtremeCast Games
Re: New Kid on the Block
« Reply #7 on: December 28, 2008, 09:25:31 PM »
$smarty->template_dir = 'c:/C:/xampp/htdocs/smarty/templates';
$smarty->config_dir = ' c:/C:/xampp/htdocs/smarty/config';
$smarty->cache_dir = 'c:/smarty/smarty_cache';
$smarty->compile_dir = 'c:/smarty/smarty_templates_c';

$smarty->template_dir = 'c:/xampp/smarty/templates';
$smarty->config_dir = ' c:/smarty/config';
$smarty->cache_dir = 'c:/smarty/cache';
$smarty->compile_dir = 'c:/smarty/templates_c';

On *nix machines each account has a directory that is basically there web space. In each directory is a cgi-bin folder. In that folder I put...
/cgi-bin/smarty/templates
/cgi-bin/smarty/templates_c
/cgi-bin/smarty/config
/cgi-bin/smarty/cache

I use WOS (Web Server on a Stick) for my local windows copy and for my portable jump drive... so in my www (public html) directory I create a cgi-bin directory and duplicate somewhat the same structure

c:/wwwroot/cyberstryke/cgi-bin/smarty/templates
c:/wwwroot/cyberstryke/cgi-bin/smarty/templates_c
c:/wwwroot/cyberstryke/cgi-bin/smarty/cache
c:/wwwroot/cyberstryke/cgi-bin/smarty/config


I use Smarty and ADODB in about 94% of my coding, so I put both smary and the adodb library in PHP's shared path on the server for WOS you put it in the PEAR directory they make that way i just add

include "smarty/Smarty.class.php";

That way they can be used across the server on all the games :) Makes updating to new versions nice and painless...

Ya I would check out ADODB as well for a db access layer, the biggest benefit of that library is if you use there execute query function it automatically scrubs the data for any type of SQL injection statements ;)

« Last Edit: December 28, 2008, 09:58:48 PM by codestryke »
Creating online addictions, one game at a time:

Offline AcidicOne

  • Level 16
  • *
  • Posts: 147
  • Reputation: +0/-0
    • View Profile
Re: New Kid on the Block
« Reply #8 on: December 28, 2008, 10:48:52 PM »
okay but was i correct as far as the index.php and index.tpl was concerned?
People Like You, Are the Reason People Like Me Need Medication

Offline Caesium

  • Level 4
  • *
  • Posts: 14
  • Reputation: +0/-0
    • View Profile
Re: New Kid on the Block
« Reply #9 on: December 28, 2008, 11:12:47 PM »
index.php will have code in it. It needs to instantiate the smarty class, do your business logic, and then call the display method to show a template.  The template will have only HTML and smarty code inside of it.

For example, index.php will have something like:
Code: [Select]
<?php

require("SmartyX.php");

$smarty = new SmartyX();

$smarty->assign('var1''value1');

$smarty->display('index.tpl');

?>



SmartyX is what I name my extended Smarty class.  I extend it so the cookie cutter configuration stuff is done automatically.

Your template file will look like this:
Code: [Select]
<html>
<head>
<title>Smarty example</title>
</head>
<body>

<p>var1 has the value: {$var1}</p>

</body>
</html>


index.tpl must be placed inside your templates directory.  When it is run, smarty will compile the template and create a version of the file in the templates_c folder automatically.

Offline jannesiera

  • Level 35
  • **
  • Posts: 1,026
  • Reputation: +6/-1
    • View Profile
    • BBGameDesign
Re: New Kid on the Block
« Reply #10 on: December 29, 2008, 04:27:35 AM »
I started on my game without any programming experience. I started with a framework (modulargaming), which uses OOP, php scripts and smarty. So far I'm doing very well and smarty isn't that difficult I guess.

Offline Qwerty

  • Level 12
  • *
  • Posts: 90
  • Reputation: +0/-0
    • View Profile
Re: New Kid on the Block
« Reply #11 on: December 29, 2008, 04:32:06 AM »
I started mucking around with phpBB before I started making games. I copied their template system which is a bit easier and wrote everything else myself.
- "I sentance you to life"
- "You moron I'm already alive"

Offline Zeggy

  • Global Moderator
  • Level 35
  • *****
  • Posts: 1,187
  • Reputation: +13/-4
    • View Profile
Re: New Kid on the Block
« Reply #12 on: December 29, 2008, 08:48:41 AM »
And glad to see alot of the more experianced members on the forums are not the "RTFM" manual types.

Sadly, there's no browser game manual that we could refer people to :)

You're right, that tutorial is confusing in getting an example of smarty running.

Smarty has a crash course that is very useful in showing how index.php and index.tpl work with each other: http://www.smarty.net/crashcourse.php

(Luckily, smarty has a manual :D)

Offline AcidicOne

  • Level 16
  • *
  • Posts: 147
  • Reputation: +0/-0
    • View Profile
Re: New Kid on the Block
« Reply #13 on: December 29, 2008, 01:15:36 PM »
yeah i found that eventually last night,Thanks for the link though. And yes it has a manual, but its windows documentation is well rather lacking to say the least. Maybe its just me, but I know I personally am a visual learner, so the text file instructions are giving me quite the headache. So with the index.php and index.tpl coded correctly. I would like to double check my folder locations just in case.(mainly so i can take SS's and post up the finished guide for install,there does not appear to be any other guide for a install outside of the one provided from smartys website regarding the windows version or even xampp).

Unzipping Smarty.zip to C:/smarty

then using from the php.ini

$smarty->template_dir = 'c:/xampp/smarty/templates';
$smarty->config_dir = ' c:/smarty/config';
$smarty->cache_dir = 'c:/smarty/cache';
$smarty->compile_dir = 'c:/smarty/templates_c';

now the reason i ask is because xampp is not my www folder, my htdocs is, or does this matter?
Quote
Setup these two folders INSIDE your www root:
(wwwroot)/smarty/templates (this is where your templates will go)
(wwwroot)/smarty/configs

So basically i am unzipping the smarty to c:/smarty

copying template_c and config to xampp or htdocs?
then moving my index.php to htdocs folder
and index.tpl to template_c folder in my xampp or htdocs
People Like You, Are the Reason People Like Me Need Medication

Offline grimsage

  • Level 5
  • *
  • Posts: 19
  • Reputation: +0/-8
    • View Profile
Re: New Kid on the Block
« Reply #14 on: January 29, 2009, 02:57:50 PM »
i see good information within this community

 


SimplePortal 2.3.3 © 2008-2010, SimplePortal