Page 1 of 1

PHP xtemplate question

Posted: Thu Sep 10, 2009 11:54 pm
by dude81
Hello,
I've been coding a product with xtemplate. It is of MVC Architecture. I've an index file which has its own xtemplate output.
In the index file, I would also like to put the view of various modules which would have different xtemplate output according to their view php logic.

Now I would like to include one php view files to one index file. Each of the view files has its own blocks inside and would display a grid of data. Now including the file has been tough. Here is the code that I'm trying to work with
PHP code

Code: Select all

 
require_once(APP_FOLDER."/themes/".$theme."/header.php");
require_once(APP_FOLDER."/themes/".$theme."/left.php");
$xtpl = new Xtemplate(TPL_DIR."clients/index.xtpl");
require_once(APP_FOLDER."/modules/clients/view.php");
$xtpl->parse('main');
$xtpl->out('main');
//require_once(APP_FOLDER."/modules/clients/view.php");
require_once(APP_FOLDER."/themes/".$theme."/footer.php");
?>
 
This outputs two of the views
index.xtpl

Code: Select all

 
<!-- BEGIN: main -->
 <div id="content_box">
<div id="content">
<div id="clientsView">
    <p align="right" style="padding-right:10px;"><input id="addClient" type="button" value="Add Client" onclick=window.location="index.php?ad=clients&af=add"></p>
    {FILE "views/clients/view.xtpl"}
</div>
</div>
 </div>
</div>
 
  <!-- END: main -->
 
views/clients/view.xtpl

Code: Select all

 
 <!-- BEGIN: main -->
 <div>
    <!-- BEGIN: row -->
    <table class="clientsView" border="0" cellpadding="0" cellspacing="1">
    <tr><th>Client Name</th><th>Email</th><th>Phone</th><th>Web</th><th>Action</th>
    </tr>
    
    <!-- BEGIN: columns -->
    <tr>
    <td>{DATA.NAME}</td><td>{DATA.EMAIL}</td><td>{DATA.PHONE}</td><td>{DATA.WEB}</td><td>Edit/Delete</td>
    </tr>
    <!-- END: columns -->
    </table>
    <!-- END: row -->
</div>
 <!-- END: main -->
 
The output seems to be just two of the view files
the view.php code is below

Code: Select all

 
require_once(APP_FOLDER."/models/Client.php");
$client = new Client($db);
$clients_list = $client->getClients();
//print_r($clients_list);
$xtpl = new Xtemplate(TPL_DIR."clients/view.xtpl");
foreach($clients_list as $clients ){
    $clients_data = array(
                        "ID"=>$clients['client_id'],
                        "NAME"=>$clients['client_name'],
                        "EMAIL"=>$clients['email'],
                        "PHONE"=>$clients['phone'],
                        "WEB"=>$clients['web'],
    );
    $xtpl->assign('DATA',$clients_data);
    //$xtpl->assign('ROW_NR', $i);
    $xtpl->parse('main.row.columns');
}
$xtpl->parse('main.row');
$xtpl->parse('main');
$xtpl->out('main');
 

Re: PHP xtemplate question

Posted: Sat Sep 12, 2009 5:55 pm
by josh
Anyway to restate this in question form? Maybe this just doesnt make sense since i dont use xtemplate but id be darned

Re: PHP xtemplate question

Posted: Sat Sep 12, 2009 8:18 pm
by dude81
Okay,
I've a product in which each module would index, add , edit, view pages.
Now in a certain module's index page I would like to call two other different modules view pages.
say in an example format, In admin modules index page, I would like to show client modules view page(which contains list of clients), projects modules view page. For this what I would do in a normal php form is I would call
in Admin Module/index page

Code: Select all

 
//Admin module Index page code and its view logic here
//In a certain div of index I would like to call client modules view page
//In a certain div of index I would like to call projects modules view page
//index page code continues
 
This is what I would like to replicate through xtemplate

Re: PHP xtemplate question

Posted: Sun Sep 13, 2009 11:26 am
by josh
I don't use xtemplate but couldnt you include the page within an output buffer and assign the output to a view variable? In Zend this is called view partials.