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


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 06-12-2007, 11:14 PM
Junior Member
 
Join Date: Feb 2007
Location: Spain, you will notice in my English ^^
Posts: 10
Post view rendering

Hi!

I'm upgradating to version 1.0.0 and I have a problem.
In IndexController I had this function:

Code:
function indexAction()
{
    $this->view = Zend_Registry::get('view');
    $this->view->title = "School";
    $this->view->actionTemplate = 'index.phtml';
    $this->_response->setBody($this->render('base.phtml'));
}
But now this doesn't work. My base is "Getting Started with the Zend Framework" by Rob Allen. Now I have to put this:

Code:
function indexAction()
{
    this->view->title = "School";
    $this->render();
}
But I lose an important thing by doing this. Before, all the views were passing first for base.phtml, wich archive made the page structure:

Code:
<html>
	<head>
		<title><?php echo $this->escape($this->title); ?></title>
		<link rel="stylesheet" type="text/css" media="screen" href="<?php echo $this->baseUrl;?>/public/styles/site.css" />
	</head>

	<body>
		<div id="wrapper">
  			<div id="header">
    			<?php echo $this->render('header.php')?>
  			</div>

			<div id="body">
   				<div id="menu">
   					<?php echo $this->render('menu.php')?>
   				</div>
   				<div id="content">
    				<?php echo $this->render($this->actionTemplate); ?>
   				</div>
  			</div>

  			<div id="footer">
  				Contact
  			</div>
		</div>
	</body>
</html>

But now, how do I do this? The way I was doing it it doesn't work now! And if I have to put the whole code in each Action is crazy!!

Thank you and sorry for the lenght!

Last edited by enkara : 06-12-2007 at 11:16 PM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 06-13-2007, 12:05 AM
Junior Member
 
Join Date: May 2007
Posts: 25
Default

rc2 has a viewRenderer that includes views automatically - so no need to call $this->render()

And this is how I render my pages:
PHP Code:
<?php $this->render('header'); ?>
   My page content
<?php $this->render('footer'); ?>
Although you do end up setting each action script - it allows you to customize each page quite nicely. And to render for example menus and such you can use view helpers to retreave the data.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 06-13-2007, 08:27 AM
Maugrim The Reaper's Avatar
Junior Member
 
Join Date: Jun 2007
Location: Ireland
Posts: 20
Default

You may not even need the $this->render() call if ViewRenderer is enabled - it's called automatically using a template of the form:

./views/scripts/{controllerName}/{actionName}.phtml

If that "specification" isn't correct for your application you can change it quite easily. Have a read here and let me know if it doesn't cover your case:

Having a bad ViewRenderer day in your ZF app? - Maugrim The Reaper's Blog
__________________
Pádraic Brady

http://blog.astrumfutura.com
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 06-13-2007, 04:45 PM
Junior Member
 
Join Date: Feb 2007
Location: Spain, you will notice in my English ^^
Posts: 10
Default

Thank you both for your ideas!

I'll try some ideas from your link Maugrim. I think that is exactly my problem!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 06-14-2007, 06:04 PM
Junior Member
 
Join Date: Feb 2007
Location: Spain, you will notice in my English ^^
Posts: 10
Default

Ok! I've found a solution. I don't know if it's good or not, but at least it works.
In IndexAction:

PHP Code:
function indexAction()
{
    
$this->view->title "School";
    
$this->view->loginError true;
    
    
$body 'index.php';
    
Zend_Registry::set('body'$body);
            
    
$this->render('base');
    return;

and in base.phtml:

PHP Code:
<div id="content">
    <?php
        $body 
Zend_Registry::get('body');
        echo 
$this->render($body);
    
?>
</div>
Thanks a loooot!!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 06-15-2007, 03:39 AM
SpotSec's Avatar
Senior Member
 
Join Date: Feb 2007
Location: United States
Posts: 121
Default

Kinda hacky... What is wrong with passing it to the view object and rendering it from there?
__________________
Zym Framework - A Zend Framework extension library w/ demo app

SpotSec Blog:
http://spotsec.com/blog
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 06-15-2007, 07:40 AM
Maugrim The Reaper's Avatar
Junior Member
 
Join Date: Jun 2007
Location: Ireland
Posts: 20
Default

Is base completely common to all Views? If so this is better added to a subclass of Zend_Controller_Action (you should have one already ). That way if you ever decide to migrate to an alternate layout solution you can do it quickly by editing 3+ lines of code instead of 3+ * no. of action methods.
__________________
Pádraic Brady

http://blog.astrumfutura.com
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 06-15-2007, 07:11 PM
Junior Member
 
Join Date: Feb 2007
Location: Spain, you will notice in my English ^^
Posts: 10
Default

Ok... I don't know anything of ZF or php, I'm just starting. Yes, base is common to absolutely all views. What happens is that I don't usually speak English and I don't know how to explain things.
I will have a look to some tutorial to find out how to use that Zend_Controller_Action. I don't have one

Tank you very much!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #9 (permalink)  
Old 06-18-2007, 07:39 PM
Junior Member
 
Join Date: Feb 2007
Location: Spain, you will notice in my English ^^
Posts: 10
Default

I have a dilemma. Do you both think that the way I'm assuring to pass first for my base archive could give me problems or it consumes too many resources?

Because I don't understand ZF API. I don't know why, I think I need more explanation and concrete examples.

First of all, I don't like the idea of disabling the viewRendering. I don't know why. Maybe because I think it's like going backwards.
Then I tried the second alternative that Maugrim offers me in his page, and changing it a bit I came to my solution.
Then I thought that that way wasn't good enough, because of your comments. I looked at the ZF API how to make that with view helpers as spotSec said. But I think that putting in each action to render the head and the footer and then in each template call the helper was too repetition of code.
Then I read Zend_Controller_action subclassing and I just don't understand how it works.

Then I read the post of another guy that wanted to do the same as me but only with the head and the foot and I found Maugrim two-step pattern. I was going to try it, but I wanted first your opinion because for me this is very complicated.

What do you think I should do? I know this is a difficult question and that I'm abusing of your amability, but I'm very lost! I just want to do a standard webpage that always shows the same things in ALL pages (head, menu, footer) and only change the content!!

Thank youuuu
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #10 (permalink)  
Old 06-18-2007, 07:53 PM
SpotSec's Avatar
Senior Member
 
Join Date: Feb 2007
Location: United States
Posts: 121
Default

well, unofficially, padraic and ralphschindler both have their unofficial components at the moment that deal with layouts. I'm sure padraic and explain his . As for ralphschindler's, you can try and ask a few people on zftalk about it. I am preparing an example zf application which *might* be using it in the next who noes (days/weeks)...
__________________
Zym Framework - A Zend Framework extension library w/ demo app

SpotSec Blog:
http://spotsec.com/blog
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 10:13 AM.