Page 1 of 1
plugin function problem [solved]
Posted: Thu Jan 25, 2007 6:15 pm
by pumuklee
hi
i create a plugin function
i use it in the template like {contornr}
but the problem is that i want to use something like this
global $gCms;
global $db;
$db =& $gCms->GetDb();
$operation = "SELECT * FROM contornr WHERE sessionid = '".$locsid."'";
$execres = $db->Execute($operation);
if($execres->RecordCount()==0)
this recorcount function gives me always call a memeber function on a non-object
what im doing wrong?
thansk
Re: plugin function problem
Posted: Thu Jan 25, 2007 6:35 pm
by Dee
Odd, the code looks alright. Check the table and field name?
This code works fine here (nothing echoed at the end):
Code: Select all
global $gCms;
$db =& $gCms->getDb();
$locsid = 1;
$query = "SELECT * FROM cms_users WHERE user_id = '$locsid'';
$result =& $db->Execute($query);
if ($result->RecordCount() == 0)
echo 'no results';
Regards,
D
Re: plugin function problem
Posted: Thu Jan 25, 2007 6:39 pm
by pumuklee
hi
i use it in this way
i create a file in plugins folder
function.contornr.php
and the function name is
function smarty_cms_function_contornr3($params, &$smarty)
{
global $gCms;
global $db;
$db = &$gCms->GetDb();
if($db)
{
//select rows which sessionid is = new sessionid
$operation = "SELECT * FROM contornr WHERE sessionid = '".$locsid."'";
$execres = $db->Execute($operation);
if($execres->RecordCount() == 0)//if not exist the new sessionid,insert new row
...
and in this way it gives me this call a memeber function on a non-object for recordcount
why?
Re: plugin function problem
Posted: Thu Jan 25, 2007 7:11 pm
by Dee
Ah, OK, I tried it as a UDT from the admin (which is much easier... but shouldn't make a difference)
This code saved as plugins/function.contornr3.php and called with {contornr3} works fine overhere:
Code: Select all
<?php
function smarty_cms_function_contornr3($params, &$smarty)
{
global $gCms;
global $db;
$db =& $gCms->GetDb();
$locsid = 1;
$query = "SELECT * FROM cms_users WHERE user_id = '$locsid'";
$result =& $db->Execute($query);
if ($result->RecordCount() == 0)
{
echo 'no result';
} else {
echo 'result';
}
}
?>
Clearing the cache from the admin might help (under "Site Admin" -> "Global Settings").
Re: plugin function problem
Posted: Thu Jan 25, 2007 7:32 pm
by pumuklee
thanks for the help
i made the mistake because i change the name of the table in db
and i forget to change it in plugin
sorry my mistake
but now i understand the plugins
so that i write soem words about plugins:
1. plugin file name must be something like this: function.thename.php
2. in file the function name which we want to call must be: smarty_cms_function_thename($params, &$smarty)
3. the error messages is a little bit poor so i say that it is useful to use echo for some data
i use it print_r() for database returned data
4. for db u can use something like this
global $gCms;
global $db;
$db = &$gCms->GetDb();
if($db)
{
//select rows which sessionid is = new sessionid
$operation = "SELECT * FROM contornr WHERE sessionid = '".$locsid."'";
$execres = $db->Execute($operation);
if($execres->RecordCount() == 0)
if the query has errors it returns memeber function on a non-object
i hope it is useful for someone