Jump to content

mvc .


leela

Recommended Posts

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

Link to comment
Share on other sites

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/

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.