Jump to content

How can I view the SQL query on Smarty?


ReactionCode

Recommended Posts

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 by javsmile (see edit history)
Link to comment
Share on other sites

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.

 

post-320474-0-57700000-1407893712_thumb.png
 

The variable $ sql is on line 615 and concatenated with line 652-653 or 656

 

post-320474-0-42408700-1407893713_thumb.png
post-320474-0-23993600-1407893714_thumb.png

 

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!

post-320474-0-57700000-1407893712_thumb.png

post-320474-0-42408700-1407893713_thumb.png

post-320474-0-23993600-1407893714_thumb.png

Link to comment
Share on other sites

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

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.

Link to comment
Share on other sites

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

  • Like 1
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...