Class Html_Pdf_Export {
var $first_name;
var $last_name;
//alot of data variables
//How I have it now
function getHtml()
{
$html = "<!DOCTYPE html>
1000 lines of code with data variables
</html>";
$this->html = $html;
return $this->html;
}
function convertToPdf()
{
//function that converts $this->html to Pdf
}
//How I want the function to be but How do I pass all the data variables?
function loadHtml()
{
$html_load_template = new Html_Load_Template('the_template_i_want_to_load_with_data_variables');
$this->html = $html_load_template;
return $this->html;
}
}
I have a class that converts Html to PDF. The html I have in that class is bloated with 1000-1500 lines of html code that eventually converts to a PDF. To make it less bloated, I decided to separate the all html to another Classs called Html_Load_Template. How do I pass all the data variables that Html_Pdf_Export has to the Class Html_Load_Template?
Thank you
Well, if I understood you correctly you just need to shift getHtml() function to Html_Load_Template class (manual work). So it would look like:
Class Html_Pdf_Export {
var $first_name;
var $last_name;
//alot of data variables
function convertToPdf()
{
//function that converts $this->html to Pdf
}
//How I want the function to be but How do I pass all the data variables?
function loadHtml()
{
$html_load_template = new Html_Load_Template('the_template_i_want_to_load_with_data_variables');
$this->html = $html_load_template->getHtml();
return $this->html;
}
}
and
Class Html_Load_Template {
public function getHtml()
{
$html = "<!DOCTYPE html>
1000 lines of code with data variables
</html>";
$this->html = $html;
return $this->html;
}
// other functions if needed
}
I'm not quite sure how your "Html_Load_Template" Class looks like, but basically I guess you want to outsource the "getHtml" part to a different file, right?
So if you move your code to the Load-Class...
function getHtml()
{
$html = "<!DOCTYPE html>
1000 lines of code with data variables
</html>";
$this->html = $html;
return $this->html;
}
... wouldn't it work if you get the Data via...
$this->html = $html_load_template->getHtml();