Super duper easy Code Igniter + Smarty WITH layout capabilities!

I’m deep in the midst of the forum I’m creating (more updates about it to come later) and I decided to implement Smarty into it since I’m considering releasing it for distribution at some point, and my target users would definitely be more comfortable with {$var} than <= $var; ?> or <php echo $var; ?> .

The one thing snagging me was how to incorporate a layout so I didn’t end up with 100+ template files that had the {include file=”header.tpl”} in them. Definitely a PITA and not that great if you want more flexibility.

With a little bit of trial and error, I created a library that is less than 50 lines long, works awesomely with Smarty and supports layouts.

Instructions
1. Download the latest version of Smarty from http://www.smarty.net
2. Extract the /libs folder to your application/libraries folder and rename to smarty
3. Open your favorite text editor and put the code found @http://codesnippets.joyent.com/posts/show/1966 into it.

Save as Template.php in your application/libraries folder. In the __construct() function, change the paths to suit your application. For me, I chose to place my templates folder above my application folder, and the other folders within the /smarty folder. You can also change the template extension in the layout function to something other than .tpl, if you like.

3b. If you want to load this application-wide, open up your config/autoload.php file and add “template” to the libraries array.

4. Next, create a default.tpl (or default.html, etc) file and where you would like the content displayed, put the following:
{include file="$inner_template.tpl"}
(again, you can change the tpl to something else if you wish). Save this to your templates folder.

5. To use, load the template library and then use it like so:
$this->template->layout("content_template", array("array"=>"of stuff","to"=>"use within the template"));

6. If you want to use a different layout for part of your app, simple include the following line before calling the $this->template->layout function:
$this->template->theme = "other_layout_name";

There may be better ways to do this, and I know a lot of programmers absolutely loathe template engines and will argue til the sun comes up that they serve no useful purpose and everyone should stick with pure php. However, this particular method is working very well for me and my program 🙂

I've had it

I’ve been messing around with various forum software over the past week – phpBB 3, myBB, bbpress, vBulletin. They all have their pluses and minuses, but I’ve decided to create YAFS (yet another forum software) for my site, because, frankly, I’m just totally annoyed with having to bend what I want out of my forum to what is in the aforementioned software.

Overall my main complaint is that phpBB, myBB, and vBulletin are too bloated for what I need. bbPress is charming in its simplicity but it’s actually too simple for what I want.

This should be an interesting test. I will strive to post regularly on my experiences building a forum software.

eBay Frustrations

I sold some things on half.com this week. On one of the items the buyer contacted me and asked if they could upgrade their postage (they’d paid for media but actually wanted priority). I said of course and they sent the extra few dollars to upgrade.

half.com tells you you should ship within 3-4 days and gives that date when you sell something. This particular item was sold on Tuesday and was to be shipped by Friday.

The weather here has been snowy, windy, and really really cold (-30 air temps; -50 to -60 wind chills). I live in a very rural area and as anyone who lives in such an area can attest, the roads go to shit when the weather gets like this. Moreover, I could not get out of my driveway until Friday afternoon because of the drifts we kept getting from the field across the street.

Anyway, I get an email from this buyer saying that they are angry because the package just left yesterday and that they’d figured they’d get it by this weekend and not next week, and that they purchased another item from someone even farther away and already received that item.

On the one hand, I feel really bad that I couldn’t get the package out sooner. I was going to mail it Wednesday but that’s when this latest bout of shitty weather started. Furthermore, I understand what it’s like to pay for something you need and have someone take their sweet time in mailing it. I once had someone wait (literally) 2 weeks to mail something because they forgot about the order

On the other hand, I did get this person’s item shipped within the time frame, and I normally ship things within a day or two.

So, I emailed them back and apologized for the delay, explaining the reason for it, and offered to refund their shipping. There’s really nothing else I can do. I hope they don’t get petty and leave negative feedback. I’m hoping that since they took the time to contact me about it they aren’t trigger happy, per se.

DirectI API and NuSoap Problems (and My Fix)

I’ve been struggling the past few days with getting the directI/resellerclub/whatever they are calling themselves now API to work. Much of my struggle laid with the SOAP/XML aspect.  I kept getting errors like “Error: no transport found, or selected transport is not yet supported!”, Fatal errors about class soapclient not being able to be redifined. or blank pages.

I’d downloaded the PHP Domain Kit from resell.biz/us2.net (where I have my account with) and was attempting to use that.  IMHO, the PHP kit is garbage; the only good thing you can get from that are the .wsdl files.

So what was my fix? It was so simple I couldn’t believe it! I went to SourceForge and downloaded the most recent release of NuSoap (0.7.3 as of this post), extracted the nusoap.php file from there and placed it in the directory where the old nusoap.php file was located.

After doing that, I renamed any calls utilizing soapclient_w (which is what I’d renamed class soapclient in old nusoap.php after getting the redefined error mentioned above) with nusoap_client, and it worked!

Here’s how my code looks now:

//Include the nusoap and apiutil files. I use CodeIgniter, so APPPATH is already predfined. Replace APPPATH as needed for your code so it has the correct path.
include_once(APPPATH."libraries/domains/nusoap.php");
include_once(APPPATH."libraries/domains/apiutil.php");

//This particular chunk of code will check for domain availability, but the same principle applies to pretty much all of the classes/calls. Reference the PHP files included in the DomainsKit example files to apply the appropriate apiutil function as needed. The "TRUE" refers to defining whether or not you want the API to return alternate name suggestions
$parameters = array("reseller@username.here", "reseller_password", "reseller", "en", "parent_id_here", getArrayFromString("domains,to,check,separated,by,commas"), getArrayFromString("tlds,separated,by,comas"), "TRUE");
//$this->wsdl is defined earlier in my class. It's just the server path to the .wsdl files
$directi = new nusoap_client($this>wsdl."DomOrder.wsdl","wsdl");

//For some reason, this needs to be set prior to the call() function being called. Right now it is pointing at the demo server.
$directi->endpoint = "http://api.onlyfordemo.net/anacreon/servlet/APIv3";

$result = $directi->call("checkAvailabilityMultiple",$parameters);

(If you’re getting weird block-looking thingies, it’s thanks to wordpress’s filtering. Visit http://codesnippets.joyent.com/posts/show/1931 to see it in better form).

Hopefully this well help anyone trying to utilize DirectI’s API! 🙂