Don't know better title to describe my problem.
So here's the long version:
Problem 1:
I have a php class with all the stuff in it to control a page (Languagemanagement, functions, Databasecoection etc.)
And im loading content with ajax.
Right now i have to initiate the same class for each ajax file. Which seems stupid to me.
Isn't there a way to initiate the class once as global and use it in ajax loaded files too?
Something like:
(Mainpage)
$class=new myClass();
and in Ajaxfile
$class->dosomething();
$GLOBALS not working and a $_SESSION can't store a class.
Problem 2:
How can i add new functions to my class without touching the classfile?
Example:
PHP Code:
class myClass{
private $testvar='HELLO';
public function addFunction($func=false){
//HOW TO MAKE THIS
}
function __construct(){
//Initiate
}
}
$class=new myClass();
//No i need something like this
function myfuncname(){
echo $this->testvar;
}
$class->addFunction(myfuncname);
$class->myfuncname();
//RETURN = HELLO
How do i need to create addFunction to get the needed result?
Thanks in advance
برچسب:
نویسنده: آیلین رضوانی
تاريخ: پنجشنبه
7 دی
1396 ساعت: 1:11