Skocz do zawartości
Zaloguj się, aby obserwować

[] Starting from Scratch - Hello World! - An IPB.Board 3 mod - Part 4

Polecane posty

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 GuestDo not translate this file as you will lose your translations next time you edit via the ACPPlease 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:

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 :)

Zobacz Artykuł w pełnej wersji

Udostępnij ten post

Link to postu
Udostępnij na innych stronach

Bądź aktywny! Zaloguj się lub utwórz konto

Tylko zarejestrowani użytkownicy mogą komentować zawartość tej strony

Zaloguj się, aby obserwować  

  • Kto przegląda   0 użytkowników

    Brak zalogowanych użytkowników przeglądających tę stronę.


Ważne informacje

Kontynuując przeglądanie strony, wyrażasz zgodę na używanie przez nas plików cookies.