lsantos2015 Posted February 16, 2014 Share Posted February 16, 2014 Hello. I had build a module, where I have 2 functions that i need to access from other parts of Prestashop. The module is on front, but i need to access those 2 functions from all parts, including backoffice.. Where should I put those functions to be able to call them from anywhere ? Just one more detail about DB access.. I added a new .php file, to check some info, how can I use the connection from Prestashop to make a SQL Query and echo a value to a variable ? Regards Luis Link to comment Share on other sites More sharing options...
vekia Posted February 16, 2014 Share Posted February 16, 2014 in this case, if you want to run these functions both from back and front office, moreover, also from other modules and controllers you have to create an override of controllers, unfortunately. the best thing, two files: /classes/controller/AdminController.php and /classes/controller/FrontController.php 1 Link to comment Share on other sites More sharing options...
lsantos2015 Posted February 16, 2014 Author Share Posted February 16, 2014 Hello.. Thanks for the fast reply.. Soo, about the use of DB instance.. What should i include to use DB best pratice prestashop utilities ? Best Regards Luís Link to comment Share on other sites More sharing options...
vekia Posted February 16, 2014 Share Posted February 16, 2014 DB is an global object, you can use it anywhere you want (this is what you asked for?) Link to comment Share on other sites More sharing options...
tarek.fellah Posted February 16, 2014 Share Posted February 16, 2014 Hello.. Thanks for the fast reply.. Soo, about the use of DB instance.. What should i include to use DB best pratice prestashop utilities ? Best Regards Luís this link should help you http://www.prestashop.com/blog/fr/les-bonnes-pratiques-de-la-classe-db-sur-prestashop-1-5/ Link to comment Share on other sites More sharing options...
lsantos2015 Posted February 16, 2014 Author Share Posted February 16, 2014 (edited) Hello.. Tarek.Fellah.. didn't got much help with connection or use of DB classes/functions.. Vekia.. Thanks for the reply. What i did is, with a java file, I have a live function that when you are entering text on a textfield, it checks live if a user is available or not, and for that I have a new check.php file, that is extra from prestashop engine.. and here, I don't know how to call any prestashop function, regarding DB, as nothing seems to work.. how can I call on a new extra .php file, the prestashop DB core functions ? example: <?php $var = $_POST['java_var']; $query = "SELECT * FROM "._DB_PREFIX_."table WHERE field = '$var'"; $result= Db::getInstance()->ExecuteS($query); while($row = mysql_fetch_array($result)) { $data=$row['field']; } this does not work.. how can I make this work ? Thanks for the help in advance.. Regards Luis Edited February 16, 2014 by lsantos2015 (see edit history) Link to comment Share on other sites More sharing options...
vekia Posted February 16, 2014 Share Posted February 16, 2014 you have to include two files: (path if file is located in /modules/somemodule/ dir include_once('../../config/config.inc.php'); include_once('../../init.php'); 2 Link to comment Share on other sites More sharing options...
lsantos2015 Posted February 17, 2014 Author Share Posted February 17, 2014 Hello vekia, DONE! Many thanks for your prompt reply.. Any other question, I will get in touch.... Regards Luís Link to comment Share on other sites More sharing options...
vekia Posted February 17, 2014 Share Posted February 17, 2014 you're welcome glad to hear that it works as you expected, i marked this topic as solved. with regards, Milos Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now