View previous topic :: View next topic |
Author |
Message |
raghu810 Smarty Rookie
Joined: 24 Apr 2015 Posts: 15
|
Posted: Fri Apr 24, 2015 12:10 am Post subject: Insert Function not returning the value on tpl file |
|
|
I am using the latest version 3.1.21. I have a insert function, when I call it on my template, it does not show. What could be the reason?
my function
Code: | function insert_get_status($fetch){
global $con;
$Query = "SELECT `status` FROM `pay` WHERE `id` = ".$con->qstr($fetch[id])." LIMIT 1";
$results = $con->Execute($Query);
if($fetch['id'] == "0"){
$pay = "Reversed";
} else {
$pay = $results->fields['status'];
}
return $pay;
}
|
my template call:
Code: | {insert name=get_status value=fetch id=$results[i].id assign=stat}{$stat}
|
Please help |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Fri Apr 24, 2015 2:05 am Post subject: |
|
|
Add a var_dump($results); to your function to check what your query returns. |
|
Back to top |
|
raghu810 Smarty Rookie
Joined: 24 Apr 2015 Posts: 15
|
Posted: Fri Apr 24, 2015 2:17 am Post subject: |
|
|
U.Tews wrote: | Add a var_dump($results); to your function to check what your query returns. |
It throws me this error for var_dump
Quote: | Fatal error: Can't use function return value in write context in /home/.... |
by the way, same function shows up on my admin theme, but NOT on front theme and few admin theme pages. I am unable to understand the issue. When I echo the sql query, its perfectly querying the data. |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Fri Apr 24, 2015 11:56 am Post subject: |
|
|
Have you done it like this
Code: | function insert_get_status($fetch){
global $con;
$Query = "SELECT `status` FROM `pay` WHERE `id` = ".$con->qstr($fetch[id])." LIMIT 1";
$results = $con->Execute($Query);
var_dump($results);
if($fetch['id'] == "0"){
$pay = "Reversed";
} else {
$pay = $results->fields['status'];
}
return $pay;
}
|
Other thing you can do is set $smarty->debugging = true;
Check in the debug window if $stat has any value assigned.
If you call {insert} in a subtemplate add {debug} at the end of the template file instead. |
|
Back to top |
|
raghu810 Smarty Rookie
Joined: 24 Apr 2015 Posts: 15
|
Posted: Fri Apr 24, 2015 6:53 pm Post subject: |
|
|
When I used {debug}, I got the following values:
Code: |
Smarty_Variable Object (3)
->value = null
->nocache = true
->scope = "file:dashboard.tpl"
|
When I used the var_dump($results); as suggested, it is a perfect query
Code: | object(ADORecordSet_mysql)#798 (29) { ["databaseType"]=> string(5) "mysql" ["canSeek"]=> bool(true) ["dataProvider"]=> string(6) "native" ["fields"]=> bool(false) ["blobSize"]=> int(100) ["sql"]=> string(77) "SELECT `status` FROM `pay` WHERE `id` = '1' LIMIT 1" ["EOF"]=> bool(true) ["emptyTimeStamp"]=> string(6) " " ["emptyDate"]=> string(6) " " ["debug"]=> bool(false) ["timeCreated"]=> int(0) ["bind"]=> bool(false) ["fetchMode"]=> int(1) ["connection"]=> object(ADODB_mysql)#4 (88) { ["databaseType"]=> string(5) "mysql" ["dataProvider"]=> string(5) "mysql" ["hasInsertID"]=> bool(true) ["hasAffectedRows"]=> bool(true) |
I dont understand why am i getting a null value in my debug console.
The same function is called and showing on my admin page, result is as expected but not on front user page. |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Sun Apr 26, 2015 3:54 am Post subject: |
|
|
As you can see in the var_dump $result->fields is false and not an array.
So the query did fail.
As $result->fields['status'] is undefined it's value is returned as null. |
|
Back to top |
|
raghu810 Smarty Rookie
Joined: 24 Apr 2015 Posts: 15
|
Posted: Sun Apr 26, 2015 4:21 am Post subject: |
|
|
Okay, thanks, I will look into it deeply now. |
|
Back to top |
|
raghu810 Smarty Rookie
Joined: 24 Apr 2015 Posts: 15
|
Posted: Mon Jun 08, 2015 6:25 pm Post subject: |
|
|
Am back to the issue again, now I found out the real reason why it's not been working on my templates.
My directory structure is like this.
My PHP file
root/admin/test.php
My Insert function directory path
root/functions/function.php
My template file path
root/template/theme/admin/admin-sub/test.tpl
In theme/admin/ folder, my main template file is in root/template/theme/admin/ folder and I include all sub-template files in admin-sub folder.
Which ever insert function being called in root/template/theme/admin/ folder, it is working, where as if I call the function from root/template/theme/admin/admin-sub/ folder, then the insert function wont work.
Does smarty have any restrictions on deep directories? |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Tue Jun 09, 2015 5:09 pm Post subject: |
|
|
You did not read my previous reply.
The var_dump of $result in you insert function show that the query is not returning a valid result.
$result->fields is false.
$result->fields['status'] is undefined -> your function returns a null value.
This has nothing to do with your folder structure. |
|
Back to top |
|
raghu810 Smarty Rookie
Joined: 24 Apr 2015 Posts: 15
|
Posted: Tue Jun 09, 2015 7:30 pm Post subject: |
|
|
The same very function works in 3rd level directory but not on 5th directory when I include 5th directory template file in 3rd directory template file and call the insert function. |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Tue Jun 09, 2015 8:18 pm Post subject: |
|
|
Did you check the var_dump $result->fields value for all cases?
Please do that first.
Why does the query fail. With $result->fields == false;
In your {insert} tag you use two parameter. value = fetch ???? it does not pass a variable. You pass also id , but your function has only one parameter.
Something is screwed up.
The directory levels should not be a problem. |
|
Back to top |
|
|