Sample


Creating Your Own Content

If you want to add your own custom code to the system, follow this guide. This guide is only if you wish to add pages/content/features using PHP.

Creating your own pages in PHP requires you to use the CodeIgniter framework. It's quite simple to use if you have some programming experience. You can view our test content file here: application/controllers/Sample.php

To create a page, first you will want to create a Controller file. This file will be where you main PHP code logic goes. Below is an sample controller file. The file must be saved as the same name as the class (with a captial letter). So for sample, the class here is called Sample, so the controller file must be called Sample.php. The file must be placed inside the application/controllers/ folder.

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Sample extends CI_Controller
{
public function __construct()
{
parent::__construct();
$this->load->model("user_model");
if(!$this->user->loggedin) {
redirect(site_url("login"));
}
}
public function index()
{
$this->template->set_page_title(lang("sample"));
if (!has_permission('permission_shortname', '', 'View')) {
access_denied('sample');
}
$this->template->loadContent("sample/index.php", array(
)
);
}
}
?>

The name of the Controller is also used to access the page. Since we named our controller Sample, we can now access it using our URL like so: http://www.mysite.com/sample/

This line is load the page title like below:
... $this->template->set_page_title(lang("sample"));

Make sure you add language in "application/language/english/content_lang.php"

$lang['sample'] = "Sample";
This line is user permission access:
... if (!has_permission('permission_shortname', '', 'View')) {
access_denied('sample');
}

There are a few more things to look at here too. If you notice inside the index() function, there is this line:

$this->template->loadContent("sample/index.php", array(
)
);

This line is saying to load the HTML file stored in application/views/sample/index.php. If you want to create your own HTML files, you can. Simply create a folder inside the application/views/ folder. Name it whatever you like. For this sample, let's call it sample. Inside that folder, create your very own PHP file that will be used to display the HTML. Let's create a file called test.php and put some code inside it:

Hello, this is a test! We save it as a .php file so that we can also include PHP code. Like this:

Now, we need to edit our controller file application/controllers/Eample.php to use our new HTML file that we just created. So edit the loadContent() function to use it, like so:

$this->template->loadContent("sample/test.php", array(
)
);

Now when you load the Sample page, it will display the content inside application/views/sample/test.php.

If you found that confusing, not to worry! There are thousands of guides out there that use the CodeIgniter framework. There is also the CodeIgniter Documentation, which gives a brilliant easy to understand overview of how to use the system. Don't forget to look at our own test file, which gives samples of how you can restrict access to pages (application/controllers/Test.php). You can also contact us via email if you need extra help.

CodeIgniter User Guide: http://www.codeigniter.com/user_guide/