Forums | Mahara Community

Developers /
customising mahara

07 March 2017, 19:42


I have installed mahara and started making small changes in php code.

I believe need to make huge changes in order to achieve the following:

1-Need a menu link (Navigation menu link) at the top for all type of users which would take the users to a page, say xyz.php, in the site.
2-Need to write php code for CRUD (with auto-complete search box using AJAX for searching tags)  operations in xyz.php
3-How to add php script that can be called by AJAX to get JSON data?
    This is what I tried so far:
    I tried adding 'Menu' (under Administration/Configure Site/Menus) as an Admin but it ends up in the 'links and resources'.
    Then I tried 'debugging' the code by running in IDE. Found main_nav() and standard_nav() to be responsible for menus. Can I just add an element , say 'link_to_crud', in the menu array to create a new Menu item? I am thinking I can add a static page, say 'xyz.php', somewhere in the site that can be accessed by all types of users just by clicking on the 'link_to_crud' menu link. But where and how? I do not know.

I am thinking I could copy a file under 'htdocs/view/view.php' and place it under 'htdocs/view'    or copy 'htdocs/admin/index.php' and place it under 'htdocs/admin/'. Is this the correct way to add a new "physical" page to the site?

Any page that I add should retain the theme that mahara will have at any time. What code modification will affect this when I add a new "physical" page to the site?

 I am completely lost  regarding how to make the AJAX call to my own php script to retrieve JSON data.

I have a two month deadline to complete a number of modifications to mahara and I am hard pressed for time and knowledge of Mahara. Any help would be lifesaving.

thanks in advance.


Robert Lyon's profile picture
Posts: 634

13 March 2017, 12:43

Hi Nagarajan 

Lets see if I can help.

For the menu item there is a hook to allow one to add items to the navigation menu

To use the hook you create a htdocs/local/lib.php file and in it do something like this:

// Local menu item
function local_main_nav_update(&$menu) {
    $menu['link_to_crud'] = array('path' => 'link_to_crud',
                                  'url' => 'xyz.php',
                                  'title' => 'My new one',
                                  'weight' => '50', // higher the number the later the menu item appears

This should add in a menu item on the main level of the navigation

If you want a submenu item, say under the Portfolio section, then change the first bit to:

$menu['myportfolio/link_to_crud'] = array('path' => 'myportfolio/link_to_crud',

To make a new page the best way is to copy an existing page.

To make the page fit with the system we need to do something like:

make a page htdocs/xyz.php and add the following
(based on the page being linked to under Portfolio main menu)


define('INTERNAL', 1); // if one has to log in to see the page
// define('PUBLIC', 1); // if they don't need to be logged in

define('SECTION_PLUGINTYPE', 'core');
define('SECTION_PLUGINNAME', 'view');
define('SECTION_PAGE', 'link_to_crud');
define('MENUITEM', 'groups/collections');

require(dirname(__FILE__) . '/init.php');
require_once(get_config('libroot') . 'view.php');

$form = array(
    'name'     => 'testform',
    'method'   => 'post',
    'plugintype' => 'core',
    'pluginname' => 'view',
    'elements' => array(
        'tags'        => array(
            'type'         => 'tags',
            'title'        => get_string('tags'),
            'description'  => get_string('tagsdescprofile'),
            'defaultvalue' => array('one', 'two'), // some default values for field
$renderform = pieform($form);

$smarty = smarty();
$smarty->assign('form', $renderform);
$smarty->display('xyz.tpl'); // the name of the templat eto display our page with.

And we need a template to show the form - so we create a file htdocs/theme/raw/templates/xyz.tpl
And in it put:

{include file="header.tpl"}

Here is my tags field to search with:


{include file="footer.tpl"}

That now should create a menu item that links to a page, xyz.php and on that page
should be one form field that is a 'Tags' autocomplete field

Hope that helps



2 results