ReactionCode Posted August 12, 2014 Share Posted August 12, 2014 (edited) Hi there.As a method of development controlI would like to know how I can display the result of the variable $sql, which is in the GetProducts function of class categories.phpIdeally, the variable $sql display in Smarty category page, (product-list.tpl) Thanks! Edited August 14, 2014 by javsmile (see edit history) Link to comment Share on other sites More sharing options...
vekia Posted August 12, 2014 Share Posted August 12, 2014 how you added $sql variable to smarty template? you modified controller? Link to comment Share on other sites More sharing options...
ReactionCode Posted August 12, 2014 Author Share Posted August 12, 2014 (edited) Hi Vekia I'm sorry maybe the title post is not clearly. This is my question, ¿how can I show the $sql var on smarty to check the Query result? I think that I have to edit the Category.php class to see the $Sql on product-list.tpl, but I don't know can I pass the Var to Smarty. This help me for fix my other question http://www.prestashop.com/forums/topic/349954-help-for-double-order-list/ ¿Can you help me? Edited August 12, 2014 by javsmile (see edit history) Link to comment Share on other sites More sharing options...
vekia Posted August 12, 2014 Share Posted August 12, 2014 let's clarify something. do you have your sql query ? Link to comment Share on other sites More sharing options...
ReactionCode Posted August 13, 2014 Author Share Posted August 13, 2014 Hi Vekia.Sorry for my English, maybe I not be explaining this very well, I'll try to explain with pictures. I want to load the $sql in my template to check the Query structure 1 I am referring to www.domain.com/classes/category.php and getProducts function, which is on line 560. The variable $ sql is on line 615 and concatenated with line 652-653 or 656 So if I can display on smarty the <p>Query Test: {$sql}</p> to see the result in the product-list.tpl, I will be able see how the query is built, so I can see if there is an error in my development ¿How can I pass the $sql (Only the Query) to my template? I think there should be some way to check the query builts Thanks! Link to comment Share on other sites More sharing options...
vekia Posted August 13, 2014 Share Posted August 13, 2014 $this->context->smarty->assign('sql',$sql); after that $sql will be a part of template engine, so you will be able to use it. Link to comment Share on other sites More sharing options...
ReactionCode Posted August 14, 2014 Author Share Posted August 14, 2014 Hello Vekia.I tried to pass the variable as you say but it is impossible or fails or does not load anything. If you can try on your side, and works please tell me. Best regards. Link to comment Share on other sites More sharing options...
mikecheung Posted August 16, 2014 Share Posted August 16, 2014 Vekia has given you the correct answer. I think the problem is you are putting the code in the wrong area. Usually I define smarty variables right before the .tpl call, but you will need to be sure to call the $sql variable all the way through. Why not just use : echo $sql; Link to comment Share on other sites More sharing options...
ReactionCode Posted August 16, 2014 Author Share Posted August 16, 2014 Hi Mike.Thanks for your response.I tried too the echo option on smarty, but don't work.Can you tell me where I have to insert the $this->context->smarty->assign('sql',$sql);? Link to comment Share on other sites More sharing options...
mikecheung Posted August 17, 2014 Share Posted August 17, 2014 @javsmile echo is a php function - if you just need to see the query, you can just use echo to see the query. I would need to see your code to give you specific place to place that code. you can use pastebin to share the code. Link to comment Share on other sites More sharing options...
vekia Posted August 17, 2014 Share Posted August 17, 2014 please shed more light on it. show your controller (where you include $sql to smarty variables array) and also show us what you use in the .tpl file Link to comment Share on other sites More sharing options...
ReactionCode Posted August 18, 2014 Author Share Posted August 18, 2014 I'm sorry I only know to program a little on prestashop, and this exercise is for learn more.This is my resume.On a clean Install, I'm trying to show the $SQL var of Category getproducts function, on a product list template.For that, I think that I need the Category.php Classes, CategoryController.php and product-list.tplMaybe I have to pass the $sql var from Category.php to CategoryController.php and then load the {$sql} in template product-list.tplHow can i pass the $sql "Query" to the controller, and then the controller to the template?Thanks. Link to comment Share on other sites More sharing options...
mikecheung Posted August 18, 2014 Share Posted August 18, 2014 I'm sorry I only know to program a little on prestashop, and this exercise is for learn more. This is my resume. On a clean Install, I'm trying to show the $SQL var of Category getproducts function, on a product list template. For that, I think that I need the Category.php Classes, CategoryController.php and product-list.tpl Maybe I have to pass the $sql var from Category.php to CategoryController.php and then load the {$sql} in template product-list.tpl How can i pass the $sql "Query" to the controller, and then the controller to the template? Thanks. I am going to do my best to give you an example of what you have to do based on what you are showing me. In the class getProducts () $sql = "sql query"; return $sql; Imagine that this function is a closed box, that no one can look into without you sending that information out. Return $sql is what will send the information out when you call this function. Every other variable is stuck inside the function. In the controller before the .tpl call $query = product::getProducts(); This calls the function that processes the query and defines the variable as the result from that function $this->context->smarty->assign('sql',$query ); This tells smarty that $sql = $query in the .tpl file {$sql} This display the contents for the $sql variable I hope this helps. For me, the easiest thing to do is in the class function, just use echo $sql; It will show at the top of your page 1 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