Joomla 1.5.26
Virtuemart 1.1.9
I'd like to get data from VM database in a module using the functions of ps_product.php. Some work, some don't.
Calling functions in ps_product that call other functions with "$this->" result in such an error message:
Fatal error: Call to undefined method JDocumentRendererModule::get_field() in (URL)/administrator/components/com_virtuemart/classes/ps_product.php on line XXX
I included in my code:
if( file_exists(dirname(__FILE__).'/../../components/com_virtuemart/virtuemart_parser.php' )) {
require_once( dirname(__FILE__).'/../../components/com_virtuemart/virtuemart_parser.php' );
} else {
require_once( dirname(__FILE__).'/../components/com_virtuemart/virtuemart_parser.php' );
}
require_once(CLASSPATH.'ps_product.php');
How could I resolve this problem?
Ok, I found a solution but not sure that it was perfect.
I tried to call the ps_product function in the following way:
$a = ps_product::get_field('product_id', 'product_s_desc');
That doesn't work if the called function calls other functions in the class.
Solution:
Add
$ps_product = new ps_product;
and call functions like
$a = $ps_product->get_field('product_id', 'product_s_desc');
Still some functions don't seem to work properly. For example product_has_attributes function should tell if a a product had assigned attributes or not and it returns always false.(?)
Related
I am trying to call a function from one file to another in PHP, however, I am getting the following error:
Fatal error: Call to undefined method SQLite3::print_model_query_form()
I have two files. The first - dbfunctions.php contains the method print_model_query_form().
The second file query_models contains the following code:
include_once("functions/dbfunctions.php");
$db = new SQLite3('D:\xampp\sim\htdocs\dis_sqlite_database\disSQL3.db');
print $db->print_model_query_form("query_models.php");
The function looks a little like this:
function print_model_query_form($action, $current_values = 0){
$db = new SQLite3('D:\xampp\sim\htdocs\dis_sqlite_database\disSQL3.db');
if($current_values){
// set to previous values.
}else{
// get POST values.
}
// Code to print query form.
}
Thanks in advance for any help.
Since you only hit fatal error on 3rd line, $db should be instantiated successfully. So, the issue should be the print_model_query_form method.
Referring to PHP:SQLite3 - Manual
, there is no such built in method called print_model_query_form.
[Edit 1]
Try to use require_once instead of include_once to make sure you have included dbfunctions.php successfully.
[Edit 2]
Check If you are using PHP's built in SQLite3 class (check your php.ini for extension=php_sqlite3.dll or extension=php_sqlite3.so).
If this is the case, check your dbfunctions.php for:-
class Something
new SQLite3
function print_model_query_form
If all the above exists then you should replace your 2nd line with,
$db = new Something(..);
Note: It would be better if you can show dbfunctions.php instead or letting us make assumptions based on guessing.
I am using Joomla 2.5 and DirectPHP. I can run PHP code in an article just fine. I would like to include a library of PHP functions to be available for use in all articles. What is the best way to include the function library?
I tried including (with require) from the template's index.php and even putting the functions directly in index.php, as suggested here. None of the functions are defined in the article. A test with variables and global variables also finds them undefined in the article.
I then created a custom HTML module with the PHP functions that I then used in my template, but they are still undefined in the article. Oddly enough, if I try and declare the function again in the article I get "Cannot redeclare...". How can the function be both undefined, not re-defineable?
I also tried using a namespace to define and use my functions. Same result.
Code in my custom html module:
<?php
namespace c6;
function testit5()
{
echo "hello world 5";
}
?>
Code in my article:
<?php
namespace c6;
testit5();
?>
Result:
Fatal error: Call to undefined function c6\testit5() in /home/testsite/www/www/c6test/plugins/content/DirectPHP/DirectPHP.php(58) : eval()'d code on line 5
go to,
Login to admin -> Extensions Menu -> Module Manager -> Create New Module -> Choose Custom HTML
and create you own module and add php functions.
I figured it out! My problem was the order Joomla processes things. Apparently the article is processed first, then the template. So my code using the function executed before the module that defined the function was executed. (When I got the "cannot redeclare" error, it was coming from the template, not the article.) I moved my loadposition from the template to the article and it works.
I wonder how can I find my moodle's database contents.
I want to elaborate users etc.
My first try is with PHP code using global $DB but there is an error message:
Fatal error: Call to a member function get_record() on a non-object in C:\xampp\htdocs\test.php on line 3
I use the getrecord() function but I didn't do it right.
Can anybody help me? The name of my database is "base".
Note: moodle version is 2.7.2
This is an example that should allow you to access the Moodle DB.
require_once(dirname(__FILE__).'/../../config.php'; // Insert as many '/../' as you need to get from the subdirectory your file is in, back up to Moodle's config.php
function my_function() {
global $DB;
$record = $DB->get_record('user', array('id' => 2));
var_dump($record);
}
my_function();
Hi i have uploaded a template on a website i have created using joomla and when i apply the template and visit my website i get the following error,
Fatal Error : call to a member function Fatal Error : call to a member function getCfg () on a non-object in /home/a7751589/public_html/templates/themza_j15_11/index.php on line 21.
the code on the index.php line 21 is as below.
$sliderVars['directionNav']=($this->params->get('sliderVars_directionNav')==='true' or $this->params->get('sliderVars_directionNav')==='false')?$this->params->get('sliderVars_directionNav'):'true';
please advise what i need to do to make this work,
Thank you
i recommend to checking compatibility of your theme with components...
check its http://forum.joomla.org/viewtopic.php?t=637126
Agree with GkDreamz - the "...J15..." part in your template name makes me think it's a 1.5 template that you're probably installing on a new 2.5 version.
When this happened to me, I noticed this in the PHP script:
global $mainframe;
Bear in mind that starting with Joomla 2.5, $mainframe is no longer using global, so it should be this:
$mainframe = & JFactory::getApplication();
function getContactActiveEmails($eid)
{
global $db;
if ($eid) {
$sql = "SELECT email FROM activeEmails WHERE id = $eid";
return $db->GetCol($sql);
}
}
I get the error "Cannot redeclare function getContactActiveEmails"
The line number it gives is the last line of the function - the }
All files are being called with require_once. This is the only place in the entire codebase where getContactActiveEmails is being defined. Why is this?
It is very clear from the error your function is defined twice hence you are getting the error.
I would recommend that check if the function is already defined before declaring it.
if (!function_exists('getContactActiveEmails'))
{
function getContactActiveEmails($eid)
{
global $db;
if ($eid) {
$sql = "SELECT email FROM activeEmails WHERE id = $eid";
return $db->GetCol($sql);
}
}
}
solution by #Shakti Singh will work, but keep in mind that you are loosing control of your code - you do not know where is this function declared and what does it return, so I suggest looking for it
Try case insensitive search, many text editors and IDEs search case-sensitive by default and your function can be as well declared as getcontactactiveemails somewhere.
If still no luck make php say something about this function, using Reflection extension
Example usage of reflection:
if(function_exists('getContactActiveEmails')){
$myfunc = new ReflectionFunction('getContactActiveEmails');
echo 'Function is declared in '.$myfunc->getFileName().
' starting from line '.$myfunc->getStartLine().
' to '.$myfunc->getEndLine();
die;
}
More about Reflection
I'm getting the same issue. I have a standard file called adhoc.inc.php which is imported into almost every php file on my site. With no changes being made to any code over night i started seeing the error
[13-Jul-2013 21:19:22 Australia/Sydney] PHP Fatal error: Cannot redeclare checkloggedin() in /Applications/MAMP/htdocs/mycobber/util/adhoc.inc.php on line 4
Initially I only got it in a few files so i just commented out this import and it worked. Suddenly, again no changes, I was getting this in every file i loaded. I figured this wasn't me so I restarted my MAMP servers (apache and mysql) and then it went away.
Has anyone seen this before?
This error occurs if you have your function defined in a loop, since you're trying to define it in each iteration.