Jump to content






Photo * * * * * 1 votes

Hello World! - An IPB.Board 3 mod - Part 4

Posted by rct2·com, 05 September 2009 · 470 views


Now that the structure of my application is correct, it's time to 'personalise' it. Instead of just redisplaying the calendar application, I want to replace that with my own skin, my own language, and (of course) my own code.

The function that runs in the hellosec.php file is the function called doExecute. The function that is there now from the calendar application gives one a fair idea of how to write an application. There are tests for parameters passed back in the URL ($this->request), global variables set mainly in AdminCP ($this->settings), functions to load languages and skins ($this->registry), database methods ($this->DB), information about members ($this->memberData), functions to build the output ($this->registry->output), etc.

But this blog is about some of the fundamentals, so I replace the doExecute with:

	public function doExecute( ipsRegistry $registry )
	{
		/* Load language  */
		$this->registry->class_localization->loadLanguageFile( array( 'public_hello' ) );

		/* Page Title */
		if( $this->page_title == "" )
		{
			$this->page_title = $this->settings['board_name'] . " - " . $this->lang->words['page_title'];
		}

		$this->registry->output->setTitle( $this->page_title );

		/* Navigation */
		$this->registry->output->addNavigation( $this->lang->words['page_title'], 'app=helloapp&module=hellomod' );

		/* Skin bit */
		$this->output .= $this->registry->output->getTemplate('helloapp')->sayHello();

		/* Output */
		$this->registry->output->addContent( $this->output );
		$this->registry->output->sendOutput();
		
	}

That's fairly self-explanatory I think. :unsure:

  • The line to load the language file implies we need a language file called helloapp_public_hello.php .
  • The lines to set the Page Title (which appears in the browser title bar) use a setting from AdminCP and some text from a language file.
  • A function is used to set the title
  • Some text (the Page Title from a language file again) is added to the navigation breadcrumbs with a link to the helloapp application, hellomod module.
  • A skin template bit is added to the output. This is the sayHello skin bit from the skin_helloapp.php file. The skin template bit is added to the $this->output variable.
  • Finally the output is composed and sent to the browser.

The skin file is skin_helloapp.php. In this example, it's small, containing only the SayHello skin template bit. The whole file contents are:

<?php
/**
 * Master skin file
 * Written: Sat, 05 Sep 2009 09:41:23 +0000
 */
class skin_global_1 extends output {
//===========================================================================
// Name: sayHello
//===========================================================================
function sayHello() {
$IPBHTML = "";
//--starthtml--//
$IPBHTML .= <<<EOF
<h2>{$this->lang->words['hel_heading']}</h2>
<div class='general_box'>
<p>
{$this->lang->words['hel_world']}
</p>
</div>
EOF;
//--endhtml--//
return $IPBHTML;
}

}
?>

Between them, the code and the skin templates require a few language variables ($this->lang->words['foo']) . The language file is helloapp_public_hello.php. There are very few variables, so the language file is also small:

<?php

/*******************************************************
NOTE: This is a cache file generated by IP.Board on Fri, 04 Sep 2009 12:44:22 +0000 by Guest
Do not translate this file as you will lose your translations next time you edit via the ACP
Please translate via the ACP
*******************************************************/



$lang = array( 

'hel_heading'	=> "Hello World Module Heading",
'hel_world'		=> "Hello World!",
'page_title'	=> "Hello World Example",
);

After all these edits, clicking on the 'Hello World' tab on the public board produces this result:

Posted Image


I'm not altogether sure what has happened with the green 'tab'. It has disappeared for this application and all the others too. But then again, there are a fair few folders and files that I've copied over from the Calendar application and I have no idea what they are. But I know for sure they are not correct. Clicking on 'Advanced Search' for example produces:

Fatal error: Cannot redeclare class calendarSearchDisplay in <path>/admin/applications_addon/other/helloapp/extensions/searchDisplay.php on line 20

I need to take a look at the contents of all these files and folders....

Later :)




Great tutorial :)
Fantastic Tutorial I hope IPB takes note of how this was put together, to help us less than adequate forum users (Learners) when they put their tutorials together.

BRILLIANT POST
Any progress? Looking forward to Part 5.

Tiki Tiki, on 18 September 2009 - 11:18 PM, said:

Any progress? Looking forward to Part 5.

Is there anything in particular you'd like to know? As a 'Hello World' introduction, I don't think there's much else to say really.

I haven't got explanations for any of the strange tab formatting problems, and have now started my new mod from first principles, rather than adapting the Calendar app further. Right now, I'm getting my head around hooks/overloaders and beginning to realise the benefits of hooks versus skin changes and code hacks.
Thanks for this! Nicely done!

Do you have anything like this for getting an application page to show up within the ACP?

rct2·com, on 18 September 2009 - 10:50 PM, said:


Is there anything in particular you'd like to know? As a 'Hello World' introduction, I don't think there's much else to say really.

I haven't got explanations for any of the strange tab formatting problems, and have now started my new mod from first principles, rather than adapting the Calendar app further. Right now, I'm getting my head around hooks/overloaders and beginning to realise the benefits of hooks versus skin changes and code hacks.


Awesome man, it's a great tutorial and it helps to grasp how IPB code and structure works... I ran into this error at the end of this tutorial

Fatal error: Call to a member function sayHello() on a non-object in C:\xampp\htdocs\Forum\admin\applications_addon\other\helloapp\modules_public\hellomod\hellosec.php on line 228

any ideas?

Creating an application from scratch without having to copy another app would be an AWESOME tutorial mate :)
or could it be possible to be able to download this little app? :) thanks so far, little confusing, but i'm new at this hehe, so yea... first time for everything! :) thnx!
Which Folder do you put the skin and Langauge files in IPB 3.2? Thanks

May 2012

S M T W T F S
  12345
6789101112
13141516171819
20 21 2223242526
2728293031  

Search My Blog

Latest Visitors