Matt Beckett, could you show me a simple exemple?
add_entity_relationship($file1->guid, 'my_relationship', $file2->guid);
remove_entity_relationship($file1->guid, 'my_relationship', $file2->guid);
$relationship_exists = check_entity_relationship($file1->guid, 'my_relationship', $file2->guid);
// get related files
$files = elgg_get_entities_from_relationship(array(
'type' => 'object',
'subtype' => 'file',
'relationship' => 'my_relationship',
'relationship_guid' => $file1->guid
));
$dbprefix = elgg_get_config('dbprefix');
$options = array(
'type' => 'object',
'sutype' => 'my_subtype',
'joins' => array("JOIN {$dbprefix}objects_entity ue ON e.guid = ue.guid"),
'wheres' => array("ue.title = '{$title}'")
);
$entities = elgg_get_entities($options);
Of course title needs to be sanitised, and you need to be aware that titles aren't unique, so it's much better to use guids instead
Matt Beckett! Thank you, once again you saved me.
You need to boot the elgg engine in order to use elgg functions. The easiest way to do this is to use a view if it's for output.
Put whatever it is you need in a view, and register that view as an ajax view
elgg_register_ajax_view('my/view')
Then you can access it at [url]/ajax/view/my/view
Note that the view will be public then, so add in any security limitations you may need.
If it's something more action-like (adding content to the database, relationships, etc) then you will want to use an action. Elgg has some convenience functions for accessing actions with ajax
elgg.action('my/action', {
data: {
guid: guid, //for example, whatever you want to send to your action
},
success: function() {
}
}
info@elgg.org
Security issues should be reported to security@elgg.org!
©2014 the Elgg Foundation
Elgg is a registered trademark of Thematic Networks.
Cover image by Raül Utrera is used under Creative Commons license.
Icons by Flaticon and FontAwesome.