News:

Bored?  Looking to kill some time?  Want to chat with other SMF users?  Join us in IRC chat or Discord

Main Menu

Simplest Mod

Started by RustyBarnacle, February 03, 2011, 12:09:35 PM

Previous topic - Next topic

RustyBarnacle

I'm trying to build my mod again.  I gave up on it for 2 years because even though I had one fully functional in SMF 1, I could never get anywhere in SMF2.

Is there a mod that you could recommend that is simply coded, but with enough features that a person could use as an example for learning?

Right now I'm stuck on install.php.  I can't even build the tables with the new function and I've looked through some documentation which has lots of info, but I didn't find examples which is what I learn best from.

Arantor

The simplest mod I ever saw was a single line. Point is that the simplest mod doesn't really do very much for you.

Is it just table creation that's a problem? There should be enough examples in the big thread about 2.0's functions to explain how that works, but failing that something like the 'Redirection Topics' mod has a simple(ish) example of creating new tables and how to query them. It also covers scheduled tasks as much as other things.

That's the thing - in all honesty, what you're best looking out for are mods that do different things rather than a single template for everything. There are many different things you might want to do in a mod.

RustyBarnacle

Thanks.  I know what you mean about no one mod having everything I'd need.  I think I tore apart about a dozen mods to figure out my SMF1 version but bookmarks seemed to be my go to mod for that one and I was hoping to find something similar.

If anyone has a chance to look at these 2 files, one which works for SMF1 and the other that fails for SMF2 and let me know what I'm doing wrong to achieve the same result that would be awesome.


Deaks

Quote from: Arantor on February 03, 2011, 12:25:49 PM
The simplest mod I ever saw was a single line. Point is that the simplest mod doesn't really do very much for you.

leet mod is a few words :P
~~~~
Former SMF Project Manager
Former SMF Customizer

"For as lang as hunner o us is in life, in nae wey
will we thole the Soothron tae owergang us. In truth it isna for glory, or wealth, or
honours that we fecht, but for freedom alane, that nae honest cheil gies up but wi life
itsel."

Arantor

Runic, I did a one line mod before now ;)

I don't have a code editor here so I can't really download the files to look at them - but it might help if you explain what you're trying to do...

RustyBarnacle

I'm trying to create 3 tables.  2 of them have a primary key, but most of the fields are medium int, and a few varchar.  Somehow something so simple seems to be beyond me which is why I gave up 2 years ago.

Arantor

Hmm, I don't have something handy right now to explain it. But Redirection Topics makes a table about as complex as you're after.

What you can do, though, is look at the installer SimpleDesk has. While it's a lot more complex than what you want, it's also very generic - you can turn it into any type of DB installer very easily - and it explains how to make the different tables it uses.

RustyBarnacle

Thanks!  I think that might be the ticket to what I was missing.

RRasco

Just quickly reviewing your SMF 2.x install.php file, there were a few syntax errors.  There was an extra comma after the last parameter you were providing to each function.  Try this file.

Not sure if that is it, but that was definitely not going to help.  Do you use an IDE of any kind?  I use NuSphere PHPed and it has syntax highlighting and error detection, which helps pinpoint syntax errors like this.
Vehicle Management System for SMF - SMFGarage.com

RustyBarnacle

Thanks!  I'll give that a try tomorrow.  Today I spent some time trying to use Aarantor's code but then work went sideways and my brain is fried.  43 minutes till quitting time and I can hit the door running.

RustyBarnacle

I just use notepad++ so I don't get much syntax checking.  I tried using the one you fixed for me but it also gave errors.  So I think I'm going to stick with the one I made that was adapted from SimpleDesk but it also gives an error.  Can anyone see why I'd get this error when I try to apply the mod?


Fatal error: Function name must be a string in /home/cy4410/public_html/sptest2/Packages/temp/install.php on line 203

Thanks for helping guys.


Arantor

How are you trying to run it? If you're trying to run it manually, you probably need to make sure $smcFunc is globalised.

RustyBarnacle

Do you mean this part?


<?php
global $db_prefix$smcFunc;


Those are the first 2 lines of install.php

Arantor

Hmmm.

Do you have a call to db_extend('packages'); in there anywhere (before line 203)?

Matthew K.

No, he doesn't. He also needs to remove $db_prefix and use {db_prefix} instead. In addition to some checks for SSI and so fourth.

Arantor

Except that in testing, I found cases where $db_prefix wasn't subsequently available to $smcFunc because it wasn't forced to be available in the global scope, and that's why it's declared up front in the original file from which the above is based. i.e. DON'T TOUCH IT because it works just great.

The issue is on line 203. What's on line 203?

RustyBarnacle

That's where the call to create the table at the very end is with all the arrays that were created. I'm browsing on my phone now but when I get back to my desk I'll post that line but it's the same line you used for simple desk.

Arantor

Which brings me back to my original question: how are you calling it? If you're calling it directly instead of via the package manager, did you leave the db_extend('packages'); call in?

RustyBarnacle

No, I didn't know what that was so I left it out.  I'll go try putting that in.  Thanks.

RustyBarnacle

I put this in between the global call and the $tables=array(); line:

if (SMF == 'SSI')
   db_extend('packages');

I still get the same error.

Advertisement: