Jump to content

Rate this topic

Recommended Posts

Hello dear users, not everyone know exactly how to create even a basic application in IPS 4x because of fact, that there is no HOW TO on Developers page yet. Most of 3x Developers have checked every each of Dev docs to create their own apps, i miss this "START HERE:" tutorial too so i'm about to tell all of You how to create Hello World app, i will be explaining every each of steps so there is no "why this isn't working? what i'm doing wrong?" but let me inform you that i am NOT a pro coder and I can explain some things wrong but i try my best. ^_^

So, let's begin..

STEP 1: Enabling Developer mode
I'm recommending creating own apps on forums located on localhost because of fact that the Developer Mode can mess up with your community if you do something wrong. ;)

You can download actual Developer Tools here, after downloading the files, upload them to your parent folder of your hosting (in most cases public_html). After you've uploaded files to your www hosting, create an constants.php file and put this code inside: 

<?php

define( 'IN_DEV', TRUE );

to enable Dev Mode.

More informations here:

STEP 2: Creating an Application trough your Admin CP
After completing first step, you'll need to go to your ACP and create application in ACP → System → Applications using the "+ Create new" button located on top right side of page.

SHU_0DJ2pZ.thumb.png.9d269bc2a5fdca743563852b8b62f191.png

Now you can input an Application Name, Application Directory(which is required), Author Name, Author website, Update Check URL and set the Protected status. Let's input something like this for an Hello World app:

SHU_YLlw7J.thumb.png.fa692e9c2964e5cc92f80e1231d60520.png

After inputting some strings, let's go ahead and create app by clicking Save button. Now if you look inside applications folder on your www you'll see that folder (in my case)helloworld have been created. Application Directory is actually an app key too so, remember it.

STEP 3: Developer Center
Each of app has it's own Developer Center located in ACP → System → Applications → Your Application → Dropdown menu → Developer Center

SHU_aLdGoJ.thumb.png.13c3f550bc17820b24608bd6cf6748b1.png

Inside the Developer Center is everything you need to build your own application, to set up your extensions, app settings, databases, ACP Tabs etc.

SHU_8wKGAk.thumb.png.8fe5462a716a7f8d6ca1d695be252833.png

There is also an /dev/ folder located in your app folder, there you can put an custom language strings for app(/dev/lang.php dev docs), custom templates (/dev/html/front/modulekey/filename.phtml step 3 of complete example of a plugin), custom css(/dev/css/), custom email templates(/dev/email), custom js scripts(/dev/js/) and many more..

STEP 4: Creating modules and controllers
There are two types of modules, there are admin modules which are modules showed in ACP and there are front modules which are showed on public side of forums. Because of that is just an Hello World app example, i will be showing you only front modules, so let's begin..

Like you can see on app page (yourdomain.com/index.php?app=helloworld), there is showing an error on the font side

SHU_dLGW21.thumb.png.d50a6822155c8d60c59f935423abfe36.png

It's because there is no front module and it can be easily fixed by creating an front module(which is logical), let's create one by clicking "+ Add Module" in Developer Center (STEP 3).

SHU_nL7neG.thumb.png.d6e05bdfe1e8ebec1450f4245da4e794.png

There are only two inputs(forms), Module Key and again Protected, so let's set this like that:

SHU_LraYAA.thumb.png.8d367d40607304e643777fd7568a7466.png

After putting some strings in inputs, click Save to create an module. Error isn't showing no more, but, there is no content either, there is just 2S100/1 error saying that requested page does not exist, that's because there is no controller created for this module, so let's create one by pressing + button on helloworld module.

bg.thumb.png.1e82640b6cf68ed42f8dd369e87d8fab.png

After doing that, you will see an window where you can put a filename (this is where you will be putting controller code)


SHU_P1jDRX.thumb.png.030dc95e260bd408537e37acc4ec7c17.png

Let's just call it helloworld and Save it, after doing so you'll need to set it as default controller for this module so when you visit your app on front side, there will be showing default page(default controller for default module)

SHU_vLoVWD.thumb.png.c58bf919d08f625e4ac3ae4f8da06c73.png

After doing so, if you visit your app page, there will be showing an already build-in blank template 

SHU_dLGGr1.thumb.png.a90721724fde39b24b3d7fb0e007d2b3.png

Like you can se, there is already pre-configured an language string module__helloworld_helloworld which is an module_modulename_controllername, this can be configured in /dev/ folder(mentioned in step three), so you need to go to your FTP and go to www/applications/helloworld/dev/ and open up lang.php file, there is already something inside and it's language string for app name.

 

<?php

$lang = array(
	'__app_helloworld'	=> "Hello World"
);

All you need to do is add another language string and call it "module__helloworld_helloworld" it will should be like that:

 

<?php

$lang = array(
	'__app_helloworld'				=> "Hello World",
	'module__helloworld_helloworld'	=> "Hello World"
);

 

save the file and re-upload it to the /dev/ folder, after doing so, refresh page and the title will be already there!

SHU_dLGGA1.thumb.png.e9c434acb2de467d1822f2f54c8c357c.png

but still, there is nothing inside and there is no page title. So, now we will be creating an "Hello world!" inside this page and we will add "Hello World" as page title. Open up your controller file located in yourdomain.com/applications/helloworld/modules/front/modulekey/controller.php there is already something inside it, it's automatically generated by Community Suite

 

<?php


namespace IPS\helloworld\modules\front\helloworld;

/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
	header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
	exit;
}

/**
 * helloworld
 */
class _helloworld extends \IPS\Dispatcher\Controller
{
	/**
	 * Execute
	 *
	 * @return	void
	 */
	public function execute()
	{
		
		parent::execute();
	}

	/**
	 * ...
	 *
	 * @return	void
	 */
	protected function manage()
	{
		// This is the default method if no 'do' parameter is specified
	}
	
	// Create new methods with the same name as the 'do' parameter which should execute it
}

 

More information about namespaces and classes can be found here

all you need to do is add to function execute() before parent::execute() this code:

\IPS\Output::i()->title = "Hello World";
\IPS\Output::i()->output = "Hello World!";

 

and it will be showing this:

SHU_Mq99Ao.thumb.png.c5ab7f8f287e1e86c5e16eaa02b6bffa.png

SHU_WL992O.png.98e7ff3aa3b8a9f75b58abd6f27db95b.png

but let's put this inside an template, for this, we will be needing an file inside /dev/html/ folder. But not exactly inside /dev/html/ folder, you'll need to create folders for front/admin module, modulekey. So it will be looking like that: /dev/html/front/helloworld/, now you need to create an .phtml file for template. Let's create one and put this inside:

 

<ips:template parameters="" />
<center><b>Hello World!</b></center>

 

now save it and upload to yourapp/dev/html/front/helloworld/ and name it helloworld.phtml. Now all you need to do is change a source a little bit, so instead of this code:

 

\IPS\Output::i()->title = "Hello World";
\IPS\Output::i()->output = "Hello World!";

 

You will have this code:

\IPS\Output::i()->title = "Hello World";
$tmp = \IPS\Theme::i()->getTemplate( 'modulename', 'appkey(Directory Name)', 'front' )->filename(parameters);
\IPS\Output::i()->output = $tmp;

 

after saving it you'll see this:

SHU_qLOVP3.thumb.png.dabed0afafd5a1a8946

 

Great News! You have just created an basic Hello World app with custom language strings and custom templates! Great work! 

Cheers.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Forum Statistics

    1,925
    Total Topics
    8,043
    Total Posts
×