DMCoding
DMCoding

Reputation: 1237

How to bootstrap socialengine?

I need to use some functionality exposed by an SE model as part of an AJAX call. Something like this:

<?php
header("Content-Type: application/json");
require_once("application/modules/Advancedarticles/Model/Artarticle.php");
$id = $_GET['id'] or die("Malformed instruction");
$article = new AdvancedArticle($id);
$shares = array(
    'twitter'=>$article->twitterShareCount,
    'facebook'=>$article->facebookShareCount,
);
echo json_encode($shares);
?>

No need for routing or any of that jazz.

What's the bare minimum needed to bootstrap SE in this way?

Upvotes: 1

Views: 330

Answers (1)

Ali Mousavi
Ali Mousavi

Reputation: 915

When you're developing for SocialEngine or any other platforms it's best to follow the standard structure of that platform. In SocialEngine first you create a module from the developer SDK provided by SocialEngine. You can access the SDK from SocialEngine's Package Manager.

After installing the new module you need to create a controller. This controller will fetch the data from the model and outputs it as JSON.

I'm guessing Advancedarticles is a plugin from SEAO so there should be an advancedarticles_article Model Item or something similar already defined in Advancedarticles plugin's manifest. You can check the item name in :

application/modules/Advancedarticles/settings/manifest.php

Lets say your newly created module name is Myapi and your controller is located at :

application/modules/Myapi/controllers/ArticleController.php

Controller code :

<?php

 class Myapi_ArticleController extends Core_Controller_Action_Standard
 {

    public function sharesAction()
    {
        $id = $this->_getParam('id');

        $article = Engine_Api::_()->getItem('advancedarticles_article', $id);

        $shares = array(
            'twitter'=>$article->twitterShareCount,
            'facebook'=>$article->facebookShareCount,
        );

        $this->_helper->json($shares);
    }

 }

Then you call it with :

http://localhost/myapi/article/shares/?id=XXX

Upvotes: 3

Related Questions