Matrix PHP API - Creating Standard Page Assets

By Anton Babushkin posted on 28 Feb 2011

So, why would I use it?

This is the first question that I would typically ask, and the truth is, usually you don't need to. Matrix offers a lot of functionality out of the box. For example, there is a powerful SOAP API. You'll need to make a judgement call on your particular scenario and situation. However, here is when I've typically found myself using the PHP based API:

  • Performance - making large amounts of calls over HTTP can be slow in certain environments.
  • Integration - I have an application outside of Matrix and I need them to talk and SOAP simply won't suffice.
  • Limitations


Before you can execute any PHP code directly from the terminal, you will need to make sure that you have the "php5-cli" package installed.

To install run the following command:

sudo apt-get install php5-cli

The code

Below is the code that you will need to run to create Standard Page assets. For full instructions on how to run this code, refer to the section below.

There are a couple of things you'll need to take note off so be sure to read the comments (or evil exception monkeys will come and attack you).

// First, include the Matrix bootstrap
// When ever a user makes any request to a Matrix page, this file is loaded (i.e. in the index.php file)
$SYSTEM_ROOT = "/home/websites/mysource_matrix/";
require_once $SYSTEM_ROOT . "core/include/init.inc";
// Now we need to log in
// The easiest user to work with is Root User
$root_user = $GLOBALS["SQ_SYSTEM"]->am->getSystemAsset("root_user");
if (!$GLOBALS["SQ_SYSTEM"]->setCurrentUser($root_user)) {
  echo "Could not login as root user";
// Retrieve the parent asset
$PARENT_ID = "XXXXX"; // replace XXXXX with the asset id of the parent you wish to be using
$parent = $GLOBALS["SQ_SYSTEM"]->am->getAsset($PARENT_ID);
// Load up the asset we wish to be creating
$asset = new Page_Standard();
// Define it's starting attributes
// These are the same attributes you would find if you were to right click in the asset map and select the "New Child" option
$asset->setAttrValue("name", "A simple web page");
// Now let's specify where it should be linked and how (i.e. is it TYPE_2?)
$linky = array(
    "asset" => $parent,
    "link_type" => SQ_LINK_TYPE_2,
    "is_dependant" => 0,
    "is_exclusive" => 0,
// Piece of pie. Create the asset!
if (!$asset->create($linky)) {
  echo "Could not create asset\n";
else {
  echo "Asset created: " . $asset->id . "\n";

Running the script

To run the script, follow these instructions:

  1. Create a file in your /home/websites/ directory and call it "asset_builder.php"

    cd /home/websites/

    pico asset_builder.php

  2. Copy and paste the code from above in to this file
  3. Replace "XXXXX" to the parent asset ID where assets will be created
  4. Save and run the script from the terminal:

    sudo php asset_builder.php


There are currently no comments for this article. Why not be the first to post a comment?

Build your own search

By Ladoo posted on 20 Oct 2011

You can create your own personal Search Page to assist with locating and editing the content you look after. This can be especially helpful in larger systems where quick search becomes less accurate.

Output content to a file

By Ladoo posted on 17 Nov 2011

As well as HTML and text, Matrix can be configured to directly output XML, iCal, RTF and even Word and Excel documents, so that users can directly download and work with these files.

Dynamic Asset Listings

By Liam Coltman posted on 14 Aug 2010

Learn how to make you asset listings dynamic so they can be reused across multiple pages on your site

Comment all you want

By Liam Coltman posted on 08 Sep 2011

Using a combination of an Asset Builder and an Asset Listing in Mysource Matrix can allow you to create a comment area in your website and can be used for blogs.

Trigger happy images

By Liam Coltman posted on 23 Aug 2010

Triggers are a very powerful feature in MySource Matrix. Learn how to set up a trigger to create image varieties

Pretty as a picture Image Gallery

By Liam Coltman posted on 13 Nov 2010

Image Galleries can help to add a bit of colour to your website. With a little bit of tinkering you can make an image gallery that will rival the Louvre


By Ladoo posted on 23 Feb 2012

Most content management systems only offer basic search functionality, and Matrix is no exception.

News delivered to your doorstep

By Liam Coltman posted on 10 Sep 2010

With users becoming more and more demanding on their news and website updates RSS provides the perfect option to keep readers up to date with what is happening on your site.

Release notes for Matrix 1.2

By Anton Babushkin posted on 16 Jul 2013

You can create your own personal Search Page to assist with locating and editing the content you look after. This can be especially helpful in larger systems where quick search becomes less accurate.

Paint Layouts

By Liam Coltman posted on 06 Mar 2010

The best way to think of a Paint Layout is a Design File for your page content.