Ning Developer Docs

Hi all,

I made my own content called test_content like this:

$content = XN_Content::create('test_content', 'test only', 'this is just a test')
->my->add('testAttr1',10)
->my->add('testAttr2',1000)
->save();


But I dont know how to load it again. In this link there is a a reference about XN_Content::load($content), but I am confused on how to use it. Anyone can enlighten me? I want to load the content in another page, and probably edit it and resave it.

And also after testing the code over and over again, when i tested this

https://appname.ning.com/xn/atom/1.0/content(type='test_content')


I get a lot of feeds of the same name like this:
Content feed for appname
test only
this is just a test
test only
this is just a test
test only
this is just a test
test only
this is just a test
test only
this is just a test
test only
this is just a test
test only
this is just a test
test only
this is just a test
test only
this is just a test

Is there a way to delete those contents? Again I saw XN_Content::delete(), but I'm not sure how to fill the parameters, as I don't know what is the id of the content..

I really appreciate if anyone can give me a working php sample for using this.
Thanks in advance for the reply :)

Views: 2

Replies to This Discussion

I have found the answer by myself. I will answer it so that it will be easier one needs in the future.

To use load and delete you will need the content id. We can get content ID from atom feed.

This is example code in php:

$url = "https://" . $apphostname . "/xn/atom/1.0/content(type='test_content')";
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_POST, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_USERPWD, $appOwnerId.':'.$appOwnerPwd);
$result = curl_exec($curl);
$retcode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
$xml = new SimpleXMLElement($result);

foreach($xml->entry as $entry) {
// extract content id
preg_match('/\/[^\/]+$/', $entry->id, $matches);
$contentId = substr($matches[0], 1);

// if you want to delete content
XN_Content::delete($contentId);

// if you want to load the content object
$contentObject = XN_Content::load($contentId);
// you can access your attribute by using $contentObject->my->myAttribute
}


Or another way is to use XN_Query
$q =XN_Query::create('Content')
->filter( 'type', 'eic', 'test_content')
->execute();
Thanks. That should be useful.

RSS

© 2026   Created by Ning Developer Admin.   Powered by

Badges  |  Report an Issue  |  Terms of Service