franklinfs Posted October 11, 2013 Share Posted October 11, 2013 Hi How i do i get the url in tpl file for the module. Link to comment Share on other sites More sharing options...
vekia Posted October 11, 2013 Share Posted October 11, 2013 here is the example: {$link->getModuleLink('mymodule', 'somecontroller')} 2 Link to comment Share on other sites More sharing options...
franklinfs Posted October 11, 2013 Author Share Posted October 11, 2013 hi this is my code. how can i use the code here? $.ajax({ type: 'POST', url: '/abc.php', data: 'risk_id=1', success: function(data) { alert(data); } Link to comment Share on other sites More sharing options...
vekia Posted October 11, 2013 Share Posted October 11, 2013 {literal} $.ajax({ type: 'POST', url: '{/literal}{$link->getModuleLink('mymodule', 'somecontroller')}{literal}', data: 'risk_id=1', success: function(data) { alert(data); } {/literal} Link to comment Share on other sites More sharing options...
franklinfs Posted October 15, 2013 Author Share Posted October 15, 2013 Actually i am not using controller file in my module! Link to comment Share on other sites More sharing options...
vekia Posted October 15, 2013 Share Posted October 15, 2013 so how you want to display module page? can you shed some light on this what exactly you've got now? Link to comment Share on other sites More sharing options...
franklinfs Posted October 15, 2013 Author Share Posted October 15, 2013 Sorry. Actually i am new for prestashop. i am trying to create a backend module. So i create a php file and one tpl file. when i install this module i can able to see a icon in back end. when i click this image i want to execute a function in the php file using ajax. for example mymodule.php if(isset($_REQUEST['id'])) { $res = "123"; echo $res; } in my tpl file(mymodule.tpl) function abc() { $.ajax({ type: 'POST', url: 'mymodule.php', data: 'id=1', success: function(data) { alert(data); } }); } Link to comment Share on other sites More sharing options...
vekia Posted October 15, 2013 Share Posted October 15, 2013 but this is full code of your .php file? Link to comment Share on other sites More sharing options...
franklinfs Posted October 15, 2013 Author Share Posted October 15, 2013 (edited) no. all the things are working. but now my requirement is when i click an icon from this tpl file i need to acccess one of the function from the php file now the problem is only the url. I give the direct url in ajax function like.... http://host name/modules/mymodule/mymodule.php Edited October 15, 2013 by franklinfs (see edit history) Link to comment Share on other sites More sharing options...
vekia Posted October 15, 2013 Share Posted October 15, 2013 it isn't working like this. in what hook you use .tpl file ? if you want to use method you mentioned (ajax) you have to create additional module .php file (separated not related to mymodule.php) Link to comment Share on other sites More sharing options...
franklinfs Posted October 15, 2013 Author Share Posted October 15, 2013 i am using this hook - displayBackOfficeTop Link to comment Share on other sites More sharing options...
vekia Posted October 15, 2013 Share Posted October 15, 2013 create php file, for example ajax.php with content: <?php include_once('../../config/config.inc.php'); include_once('../../init.php'); include_once('mymodule.php'); $mymodule = new mymodule(); $mymodule -> somefunctionfrommodule(); then in call this file in your ajax call. code defined in public function somefunctionfrommodule(); will be called then 1 Link to comment Share on other sites More sharing options...
franklinfs Posted October 17, 2013 Author Share Posted October 17, 2013 Hai Thanks Thanks a lot for your help Link to comment Share on other sites More sharing options...
vekia Posted October 17, 2013 Share Posted October 17, 2013 hello just wondering: have you achieved what you expected? Link to comment Share on other sites More sharing options...
franklinfs Posted October 17, 2013 Author Share Posted October 17, 2013 yes Link to comment Share on other sites More sharing options...
vekia Posted October 17, 2013 Share Posted October 17, 2013 ok, thank you for confirmation im so glad that i could help you a little now im going to mark this topic as [solved] with regards, Milos Link to comment Share on other sites More sharing options...
Recommended Posts