Skip to content

Instantly share code, notes, and snippets.

@ababushkin
Created September 21, 2011 23:36
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ababushkin/1233623 to your computer and use it in GitHub Desktop.
Save ababushkin/1233623 to your computer and use it in GitHub Desktop.
PHP - Create an asset in Squiz / MySource Matrix
<?php
// 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/squiz_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
$GLOBALS['SQ_SYSTEM']->am->includeAsset("page_standard");
$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";
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment