The idea behind my code is to create a modular system to create websites using php as a template.(It does not matter if that has all ready been done
I have had a look over the internet but have not managed to find any "python to php equivalents".
my code is as follows:
(note: I'm using WAMP to execute the code. )
Code: Select all
class website{
function __construct($title,$midhead,$body_attr,$scripts){
$this->$upper="<!DOCTYPE html> \n <html>";
$this->$head=new head($title,$midhead,$scripts);
$this->$body=new body($body_attr);
$this->$lower="</html>";
}
function return_all(){
return $this->$upper.$this->$head->return_all().$this->$body->return_all().$this->$lower;
}
}
class head{
function __construct($title,$midhead,$scripts){
$this->$upper="<head>\n<meta name='RIZZA'> \n<link rel='shortcut icon' href='../img/main.ico'/>";
$this->$title="<title>".$title."</title>\n";
$this->$midhead=$midhead."\n";
$this->$scripts=$this->addscripts();
$this->$lower="</head>\n";
}
function return_all(){
return $this->$upper.$this->$title.$this->$midhead.$this->$scripts.$this->$lower;
function addscripts($scripts){
$script="<script src='../js/jwplayer/jwplayer.js'></script>/n<script src='../js/audiojs/audio.min.js'";
foreach($scripts as $item){
$script=$script."<script type='text/javascript' src='".$item."'></script>\n";
}
return $script;
}
}
}
class body{
function __construct($body_attr){
$this->$upper="<body ".$body_attr.">/n";
$this->$midbody="";
$this->$lower="</body>";
}
function addcontent($content){
$this->$midbody=$this->$midbody.content;
}
function addvid($vidsrc,$imgsrc,$id){
$this->$midbody=$this->$midbody.
'<div id="'.$id.'">Loading the player...</div>
<script type="text/javascript">
jwplayer("'.$id.'").setup({
file: "'.$vidsrc.'",
image: "'.$imgsrc.'",
});
</script>';
}
function addaudio($src){
$this->$midbody=$this->$midbody.
'<p style="visibility: hidden;">
<audio src="'.$src.'" preload="none" autoplay loop style=" visibility: hidden;"/>
</p>';
}
function return_all(){
return $this->$upper.$this->$midbody.$this->$lower;
}
}
1. have I got it all wrong?
2. Is the "__construct" method the same as the "__init__" constructor method from python.
3. Is "$this" equivalent to "self" in python and dose it need to be passed as an argument into the function.
4. Is the "->" equivalent to that the "." does in python.
5. Is there anything wrong with just doing
Code: Select all
$x="hi"Code: Select all
var $x=hi7. how do you recall methods of a class e.g
Code: Select all
$a=new website("hi","","","");
echo $a->return_all()