leela Posted July 7, 2011 Share Posted July 7, 2011 Hi, I am trying to implement mvc to the clumpsy code where php,html are together.. how can i separate html from php.. i have mysql.php-->where connection to databse exists. classfunc.php-->where all functions required for viewing the data are there.. view.php-->where the html file is there.. how can i combine these 3 files. without using a single echo or print can the html exists ..? for displaying the data .. here is view.php <?php include_once("MYSQLDB.php"); include_once("classFunc.php"); include_once("classFuncSF.php"); $link=MYSQLDB::connect('localhost','root',''); classFuncSF::do_list($link); ?> <table border=1 cellpadding=3 style="font-size:11px;font-family:verdana;background-color:e4e4f4;"> <tr><td colspan=10 align=center><b>Customer List</b></td> <tr align=center> <?php foreach ($columns as $column ) { ?> <td align=center><b><?php echo $column; ?></b></td> <?php } ?> i dont want even these echoes here........Please don't suggest to use any frameworks now.... Thanks in advance Quote Link to comment https://forums.phpfreaks.com/topic/241377-mvc/ Share on other sites More sharing options...
xyph Posted July 8, 2011 Share Posted July 8, 2011 Unless you want to design a template engine, you're stuck with echos. Design your html files with special variables <tr align=center> {loop:column} <td align=center><b>{column}</b></td> {end:column} And use a function to grab the HTML between the tags, loop through an array, and fill each value into column. This can get quite complicated though, and I know you didn't want me to but http://www.smarty.net/ Quote Link to comment https://forums.phpfreaks.com/topic/241377-mvc/#findComment-1239877 Share on other sites More sharing options...
gizmola Posted July 8, 2011 Share Posted July 8, 2011 There are plenty of 3rd party template class libraries you can find. This list is a little old but it gives you a starting point: http://www.livexp.net/technology/php/top-25-php-template-engines.html Quote Link to comment https://forums.phpfreaks.com/topic/241377-mvc/#findComment-1239899 Share on other sites More sharing options...
gizmola Posted July 8, 2011 Share Posted July 8, 2011 You should also take a look at zend_view from the zend framework. Even if you don't end up using one of them, you can see how the approached the problem, which will help you better understand what would be involved in rolling your own soluiton ala xyph's suggestion. Many people don't realize that while ZF includes a full mvc, you can use many pieces including the zend_view by itself. Quote Link to comment https://forums.phpfreaks.com/topic/241377-mvc/#findComment-1239902 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.