Nested HTML pages

Hi there folks. I don`t understand what is nested html pages and how to implement it. Could you please give me a simple example of it? Thank you!

do you mean frames?

This is first time I hear for nested html pages. Where you found them? Is it Yii related question?

nested views or templates?

well, I`m confused too…I got a task in russian language and one of them literally translating as a ‘nested html pages’. If its nested views then I do know what is it. But what about frames?

Well, we certinaly need more information, if we should try to help you. But, if your task is about frames, than it is bad, because frames are bad! :]

yeah, frames are evil, but sometimes iframe is the fastest and easiest way to satisfy a client (yes, we are all sinners)

Returning to the main topic, sega, what is your initial task and how is it connected to Yii?

also here is Nested ASP.NET Master Pages, but it’s definitely not about Yii.

I would completely agree with you about iframes, if we would be talking about static HTML page. But since we’re discussing dynamic, PHP-generated pages, then I think that there is absolutely no differences between IFRAME tag specifying some source route and a simple DIV loading it’s contents from the very same source route via AJAX.

Of course – by saying “no differences” I mean no disadvantages per user or developer in using DIV, because there are many advantages, that IFRAME doesn’t have. For example - security, because for AJAX loaded DIV you can secure your route (action) that it is available only for ajax-type calls and therefore not public available. While for IFRAME you need a standard, accessible route, which address a nasty user can figure out of source code and use it to do some bad, bad things! :]

My task is:

"…Section 2. Static pages

a) Tree structure (nested pages);


Any ideas guys?

but what is the action? do you need to create tree structure? with what? Looks like a sitemap to me…


So, they told me like following:

"When you creating a page, you must fill the content, title, meta-tags etc. and set the parent page".

This is reminds me OOP.

I’m 100% sure, you’re talking about some kind of CMS (Drupal, Joomla etc.) when you create content there you can select “parent” page. That has nothing with nested html, it’s just a way to organize site navigation.

Well, the work must be done using Yii :wink:

I`ll try to make it with frames.

But it has nothing to do with the frames!

Dynamic page (view) filling with some data is one of the basis of how Yii’s rendering pages. Look at any example in tutorials or in hundred of examples in the forum.

In your view file (placed in protected/views/[controller-name]/[view-name].php) put something like this:

<div class="header"><?php echo($header) ?></div>

<div class="title"><?php echo($title) ?></div>

<div class="contents"><?php echo($contents) ?></div>

<div class="footer"><?php echo($footer) ?></div>

and in your controller file you render this view with setting proper variables values, like this:

$this->render('index', array


    	'header'=>'This is header. You can put whatever, you want in here...',


    	'contents'=>'HTML tags like <strong>strong</strong> and <em>emphasis</em>...',



So, as you can see, you can fill your view with anything you need - static text, variable value, HTML code or result of executing any function.

And there you have as simplest as possible example of dynamic page filling / rendering.

Man, these are Yii total basics! Run at least demo example that comes with Yii or look at Yii Blog Demo in the resources. You’ll find everything there.

Ah, view files? ive already familiar with them.. I implemented my task like this but the boss told me Im wrong. Thats why I decided to ask people on forum.

Your boss knowns Yii better than you? :]

I guess it is. Thats why he`s boss :)

Anyway, Im still a little bit confused. You see, me as a user, must be able to create a new page, set the title, fill the content and set the parent page which our new one will be derived from. I just havent understood yet how to create a new php-file and determine the parent page were extending from, in code. If Im wrong, feel free to correct me!

Thank you.

P.S. By the way, don`t you know what extension would allow me to drag my createed objects in GridView?

It’s already part of Yii - look at how to use layouts and views.

However, to really satisfy your boss, why not look into this template extension? ->


Highly recommended.

Using phpti:

So, how does views and layouts work in Yii?

A layout:

<?php $this->beginContent('//layouts/main'); ?>

	content here

<?php $this->endContent(); ?>

That code wraps the main layout - in other words: it replaces <?php echo $content; ?> in layouts/main.php with the content within the wrap.

That’s the most basic form of reuse.

For more advanced stuff, you can look into the template extension above.


Other tools:

CClipWidget, regular CWidgets, CPortlets …