[SOLVED] How to return application/json from module
Posted: Thu Feb 28, 2013 9:31 am
I want to return clean json response from my module action on the frontend for process it by backbonejs or jquery, my question is how can I do it? In my module directory named Recipes I have file: action.get_recipes.php which contains this:
genrated link (get_recipes_url) is:
which shows:
$this->json():
I want to return clean json for that, how to do it?
I'm using 1.11.4.
Code: Select all
<?php
if (!isset($gCms)) exit;
$recipesPerPage = $this->GetPreference('recipes_per_page', 6);
$recipes = $this->prepareRecipes(array('status' => 1), array(), $recipesPerPage, 0);
$this->smarty->assign('recipes', $recipes);
$this->smarty->assign('get_recipes_url', $this->CreateFrontendLink( $id, $returnid, 'get_recipes', $contents='', $params=array('disable_theme' => true), $warn_message='',
$onlyhref=true, $inline=true, $addtext='', $targetcontentonly=false, $prettyurl='' ));
$this->smarty->assign('module_js_url', $this->getJsPath());
echo $this->ProcessTemplateFromDatabase((!empty($params['template']) ? $params['template'] : 'recipes_list'));
Code: Select all
http://local.mydomain/index.php?mact=Recipes,m1b0ee,get_recipes,1&m1b0eedisable_theme=1&m1b0eereturnid=18
Code: Select all
</__body>
<a class="top-header" href="http://local.mydomain">Â </a>
<div class="top-menu">
<ul>
<ul>
<li><a href="http://local.mydomain/main/e-sklep"><span>E-SKLEP</span></a>
</li>
<li><a href="http://local.mydomain/produkty"><span>Produkty</span></a>
</li>
<li><a href="http://local.mydomain/firma"><span>Firma</span></a>
</li>
<li class="menuactive"><a class="menuactive" href="http://local.mydomain/przepisy"><span>Przepisy</span></a>
</li>
<li><a href="http://local.mydomain/dieta-dr-budwig"><span>Dieta dr Budwig</span></a>
</li>
<li><a href="http://local.mydomain/kontakt"><span>Kontakt</span></a>
</li></ul></li>
</ul>
</div>
<div class="top-section">
<div class="slider shadow"><img src="uploads/images/mydomain/slider_content_1.png" alt="" /></div>
<!-- start content -->
[{"id":"1","title":"Testowy przepis nr 1","photos":["http:\/\/local.mydomain\/uploads\/_CGSmartImage\/krajobrazy-lasy-1600-1200-38791-ad91520efd25a36d90ff1729de5d75f2.jpg","http:\/\/local.mydomain\/uploads\/_CGSmartImage\/schab z bratkiem pan duza-5218033963887f68c2076d681bcf650f.jpg"]},{"id":"2","title":"Testowy przepis nr 2","photos":["http:\/\/local.mydomain\/uploads\/_CGSmartImage\/krajobrazy-lasy-1600-1200-38791-ad91520efd25a36d90ff1729de5d75f2.jpg","http:\/\/local.mydomain\/uploads\/_CGSmartImage\/schab z bratkiem pan duza-5218033963887f68c2076d681bcf650f.jpg"]},{"id":"3","title":"Testowy przepis nr 3","photos":["http:\/\/local.mydomain\/uploads\/_CGSmartImage\/krajobrazy-lasy-1600-1200-38791-ad91520efd25a36d90ff1729de5d75f2.jpg","http:\/\/local.mydomain\/uploads\/_CGSmartImage\/schab z bratkiem pan duza-5218033963887f68c2076d681bcf650f.jpg"]}]
Code: Select all
public function json($params) {
header('Content-type: application/json');
exit(json_encode($params));
}
I'm using 1.11.4.