Welcome, Guest. Register Now!
   
Mark Forums Read Mark Forums Read Mark Forums Read


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 03-26-2007, 12:58 PM
Cristian's Avatar
Administrator
 
Join Date: Feb 2007
Location: Sibiu, Romania
Posts: 99
Default Multiple template systems with one Zend_View object

Hello,

I am trying to use on same object multiple Template Systems with just one Zend_View (in fact derived from Zend_View_Interface) object.

Sample: i want to use both Zend_View default template system and also Smarty (sample of using Smarty is here: Zend Framework)

I don't want to create multiple Zend_View (or derived from Zend_View_Interface), because there are lot of data to be assigned to Zend_View (or similar) object...

I am wondering if could be any problems when using multiple Template systems into same object ? Also, any tips for doing such Zend_View_Interface based class...
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 03-27-2007, 12:31 AM
SpotSec's Avatar
Senior Member
 
Join Date: Feb 2007
Location: United States
Posts: 116
Default

It can be done by writing your own implemented Zend_View_Interface, but I wonder why this would be necessary?

Or you could extend the Zend_View class to include smarty. Another factor is you can chain parse the templates as I would assume you aren't passing the same data to both template engines?

$view->data = test;
$smarty->name = someName;
$view->render($smarty->render(index.tpl));

Last edited by SpotSec : 03-27-2007 at 12:35 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 03-27-2007, 06:09 AM
Cristian's Avatar
Administrator
 
Join Date: Feb 2007
Location: Sibiu, Romania
Posts: 99
Default

Hi and thanks for replies,

I am trying to simplify the use of view component due to fact i don't like too much to send lot of data to two views, and better to just one...
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 03-28-2007, 02:52 AM
quannm0410l's Avatar
Junior Member
 
Join Date: Mar 2007
Posts: 11
Red face

Quote:
Originally Posted by SpotSec View Post
It can be done by writing your own implemented Zend_View_Interface, but I wonder why this would be necessary?

Or you could extend the Zend_View class to include smarty. Another factor is you can chain parse the templates as I would assume you aren't passing the same data to both template engines?

$view->data = test;
$smarty->name = someName;
$view->render($smarty->render(index.tpl));
Can you give me a example? I want to display a loop values in views. Thank you
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 03-28-2007, 03:15 AM
SpotSec's Avatar
Senior Member
 
Join Date: Feb 2007
Location: United States
Posts: 116
Default

Quote:
Originally Posted by quannm0410l View Post
Can you give me a example? I want to display a loop values in views. Thank you
Which part would you like an example of? And what is a "loop values", I assume you are talking about array values generated from a loop statement such as foreach().

In this case you would just send the array to the view object and parse through it with Zend_View or your own template system.

Here is the Zend_View example taken from the manual.
PHP Code:
<?php // Controller script
// use a model to get the data for book authors and titles.
$data = array(
    array(
        
'author' => 'Hernando de Soto',
        
'title' => 'The Mystery of Capitalism'
    
),
    array(
        
'author' => 'Henry Hazlitt',
        
'title' => 'Economics in One Lesson'
    
),
    array(
        
'author' => 'Milton Friedman',
        
'title' => 'Free to Choose'
    
)
);

// now assign the book data to a Zend_View instance
Zend_Loader::loadClass('Zend_View');
$view = new Zend_View();
$view->books $data;

// and render a view script called "booklist.php"
echo $view->render('booklist.php');
?>
PHP Code:
<?php // View script (booklist.php)
if ($this->books): ?>
    
    <!-- A table of some books. -->
    <table>
        <tr>
            <th>Author</th>
            <th>Title</th>
        </tr>
        
        <?php foreach ($this->books as $key => $val): ?>
        <tr>
            <td><?php echo $this->escape($val['author']) ?></td>
            <td><?php echo $this->escape($val['title']) ?></td>
        </tr>
        <?php endforeach; ?>
        
    </table>
    
<?php else: ?>
    
    <p>There are no books to display.</p>
    
<?php endif; ?>
I feel like this isn't what you where looking for . In that case sorry for the misunderstanding, could you rephrase your question?

Last edited by SpotSec : 03-28-2007 at 03:19 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 03-28-2007, 04:09 AM
quannm0410l's Avatar
Junior Member
 
Join Date: Mar 2007
Posts: 11
Default

I think view layer only use to display data. I dont know put foreach loop in view is good or not but is there any way to show data without loop in there???.
"loop values" i mean it is a resultset, and use a do while loop to extract each value
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 03-28-2007, 09:38 PM
SpotSec's Avatar
Senior Member
 
Join Date: Feb 2007
Location: United States
Posts: 116
Default

Quote:
I think view layer only use to display data.
That the code there is exactly what we would consider the view. This is because if you can see all that the code does it to generate the content not the data. So the loop is perfectly valid, but something like a database query should be the part of the model.

If you really want to separate all php code, then you could use smarty or generate the html content within the controller (which basically defeats the mvc scheme)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 03-29-2007, 05:00 AM
Cristian's Avatar
Administrator
 
Join Date: Feb 2007
Location: Sibiu, Romania
Posts: 99
Default

Here are some valid methods to be used according to MVC:

Zend Framework
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 12:39 AM.