News:

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

Main Menu

How to create custom 'action'

Started by Owdy, January 09, 2005, 05:01:30 PM

Previous topic - Next topic

Johno69

Yes I have... here's the code:

<?php
if (!defined('SMF'))
die(
'Hacking attempt...');

function 
Photos() {
global 
$context;
$context['page_title'] = 'Photos';
// This is gonna be needed...
loadTemplate('Photos');
}
?>


Still not exactly sure where to put the tree stuff.

JayBachatero

#81

<?php

if (!defined('SMF'))
die('Hacking attempt...');

function 
Photos()
{
global $context$txt;

$context['page_title'] = 'Photos';

$context['linktree'][] = array(
'url' => $scripturl '?action=mypage',
'name' => $txt['mypage']
);

// This is gonna be needed...
loadTemplate('Photos');
}
?>

Follow me on Twitter

"HELP!!! I've fallen and I can't get up"
This moment has been brought to you by LifeAlert

Johno69

#82
Many Thanks.

i'm using the helios theme and i'd like the top bar (bg) to show also behind the tree, any idea how to so this.

JayBachatero

Not sure sure about that.  Look into the index.template.php file.
Follow me on Twitter

"HELP!!! I've fallen and I can't get up"
This moment has been brought to you by LifeAlert

Carinspixels

Hi I've installed a page using this code but I run into some minor errors.
i've tried adding a linkbutton on the home of my site, in the same style.

Now that works I can call the page as well, but when I go inside the admin panel and view the forum error log I get a load of errors:

http://www.ww/www/index.php 
8: Undefined index: linkbuttons
File: /home/pixellus/public_html/PI/Themes/default/languages/Shop.english.php (eval?)
Line: 473

http://www.www/www/index.php?action=linkbuttons 
8: Undefined index: linkbuttons
File: /home/pixellus/public_html/PI/Themes/default/languages/Shop.english.php (eval?)
Line: 473


Annyone know how I can fix this?

The code for the button I used is this 1 I think that is the error actually:

//linkbuttons

echo "<a href='{$scripturl}?action=linkbuttons'>", ($settings['use_image_buttons'] ? "<img src='{$settings['images_url']}/{$context['user']['language']}/linkbuttons.gif' alt='{$txt['linkbuttons']}' style='margin: 2px 0;' border='0' />" : $txt['linkbuttons']), "</a>{$context['menu_separator']}";

//end linkbuttons

Thanks so much

Peter B

Hello,
I followed all the instructions for the first post in the topic and created my Downloads.php and Downloads.template.php.
However, when I try to use downloads as an action, I get the error "Unable to load the 'Downloads' template."
I have tried a variety of changes to the code with no success.
Does anyone recognise this error and it's most likely causes.
thanks
Peter

Peter B

Hi, I worked through the problem with not able to load the template.
I added loads of debugging output in Load.php and that highlighted that the path in my default themes setting was wrong!!!
It all works fine now.
thanks
Peter B

chig

#87
I just spent hours (well I made some mistakes) to find out how to implement subactions so I thought it might be helpful for others who where searching for the same information...


Downloads.php:
<?php
if (!defined('SMF'))
die(
'Hacking attempt...');

function 
Downloads()
{
//Load the main template file
loadtemplate('Downloads');


//Downloads Actions
$subActions = array(
'subdownloads' => 'SubDownloads',
);


// Follow the sa or just go to main function
@$sa $_GET['sa'];
if (!empty($subActions[$sa]))
$subActions[$sa]();
else
main();

}

function 
Main() {
global 
$context;

$context['page_title'] = 'My Actions title!';

}

function 
SubDownloads(){
global $context;


$context['page_title'] = 'My SubDownloads!';

// This is gonna be needed...
$context['sub_template'] = 'SubDownloads';
}

?>



Downloads.template.php:
<?php

function template_main()
{
global 
$context$settings$options$txt$scripturl;

echo 
'


<table width="100%" border="0" cellspacing="0" cellpadding="3" >
<tr>
<td>'
theme_linktree(), '</td>
</tr>
</table>

<table width="100%" border="0" cellspacing="0" cellpadding="4" align="center" class="tborder">
<tr class="titlebg">
<td align="center" >Download area</td>
</tr><tr>
<td class="windowbg">'
;
 
echo 
'<table border="0" cellpadding="0" cellspacing="3" width="100%">
         <tr>
           <td width="100%" valign="top">
  MY cool downloads!!!!<br>
  <a href="'
$scripturl'?action=downloads;sa=subdownloads">SubDownloads</a> 
</td></tr></table>'
;
echo 
'
</td>
</tr>
</table><br /><br />
'
;
}

function 
template_SubDownloads()
{
global 
$context$settings$options$txt$scripturl;

echo 
'


<table width="100%" border="0" cellspacing="0" cellpadding="3" >
<tr>
<td>'
theme_linktree(), '</td>
</tr>
</table>

<table width="100%" border="0" cellspacing="0" cellpadding="4" align="center" class="tborder">
<tr class="titlebg">
<td align="center" >Sub Downloads area</td>
</tr><tr>
<td class="windowbg">'
;
 
echo 
'<table border="0" cellpadding="0" cellspacing="3" width="100%">
         <tr>
           <td width="100%" valign="top">
 This is the SubDownloads page!!!!
</td></tr></table>'
;
echo 
'
</td>
</tr>
</table><br /><br />
'
;
}

?>



with this small example it functions like a charm, unfortunatly I didn't get it into my mod I am working on so far  :-[ ... but at least I know now I am on the right track!!  :)

Maybe a moderator might add thisto first post, or a link in the first post to this post as a hint... oh and maybe this moderator might go through the code first to optimize it  ;D

Marook

SMF Rulez ;) | Meet me home ! | My Mods

King Steph1

Quote from: Owdy on January 09, 2005, 05:01:30 PM

index.php find:

'activate' => array('Register.php', 'Activate'),

ad after:

'downloads' => array('Downloads.php', 'Downloads'),
I can't find anything like that.
That's all that shows up on my index.php: <?php


// Try to handle it with the upper level index.php. (it should know what to do.)
if (file_exists(dirname(dirname(__FILE__)) . '/index.php'))
   include (
dirname(dirname(__FILE__)) . '/index.php');
else
   exit;

?>

codenaught

That's not the correct index.php file. Open the one in the root directory of your forum.

Also, are you aware there is now a mod that you can use to create custom actions?
Dev Consultant
Former SMF Doc Coordinator

King Steph1

#91
Thanks!
Everything's working now :]

Yep, but we're trying to make the board mod free.
Thanks again :)

shumar

A little help with this ?
http://www.simplemachines.org/community/index.php?topic=63203.msg1470635#msg1470635

I get page that I created above header, and below that header is Can't load main ??

Thank you in advance.

morency

how can create the wap/wap2/imode version for action=downloads , from example? :-> action=downloads;imode !

morency

 ??? ??? Please help !! any1 ! ????  how can create  the template for that example  "action=downloads" in wireless.template.php?? 

heimep

Will the custom action mod work on 1.1.5

manuxel


csulok

Hi,

Using the guide posted above (adding the action to the index.php and stuff) I created a custom action.

I don't really understand how to pass info between the action.php and action.template.php so initially I just dumped all my code into action.template.php however when I want to customize the page title I realized it can only be done in the source file, not the template one.

So my question is.. what goes into the source file usually? what goes in the template file usually? I have a few queries and show some tables based on them, how would I pass info from the query done in the source file (where based on the query results I can set the page title) to the template file?

Also, is there a way to set the page title from the template file?

Any help is much appreciated

MrMorph

An old thread I know, but still useful.

My question is the same as the one above.  What would the mod makers advise goes in each file ?  And also how to pass data between them ?

Thanks for any help.

kingkingston

Quote from: MrMorph on July 13, 2009, 02:17:01 PM
An old thread I know, but still useful.

My question is the same as the one above.  What would the mod makers advise goes in each file ?  And also how to pass data between them ?

Thanks for any help.
Maybe you should try this Mod

http://custom.simplemachines.org/mods/index.php?mod=331

Advertisement: