Hi!
Iam newbie to YII. Can some one guide me the fastest way to include '_header.php', '_footer.php' file in my main layout file labelled as 'main.php'.
Thanks in advance
Page 1 of 1
How to include other files in Layout file
#2
Posted 14 April 2010 - 08:48 AM
Personally i use the layout as the header and footer for my applications. That's the purpose of the layout file. You can do in your layout:
Will be the same as doing require for the header.php and footer.php files inside the layout.
....header stuff... <?php echo $content; ?> ...footer stuff...
Will be the same as doing require for the header.php and footer.php files inside the layout.
#3
Posted 14 April 2010 - 08:57 AM
Blue Sapphire, on 14 April 2010 - 07:26 AM, said:
Hi!
Iam newbie to YII. Can some one guide me the fastest way to include '_header.php', '_footer.php' file in my main layout file labelled as 'main.php'.
Thanks in advance
Iam newbie to YII. Can some one guide me the fastest way to include '_header.php', '_footer.php' file in my main layout file labelled as 'main.php'.
Thanks in advance
What Vince pointed out is corret. As it currently stands you'll find a file called main.php under the folder /protected/views/layout/ which holds all the information regarding the main layout of the site.
This main layout has the headers in it and the footer made at the bottom. I suppose if you really wanted to use include files for your header and footer, you could just replace the location of the header and footer in that main.php file with include("path/to/headerOrfooter");
To keep it simple, make two new files in the same directory as the main.php, call it header and the other footer that way you just have to go include("header"); or include("footer");
I think that's what you're asking unless we interpreted the question wrong.
#5
Posted 14 April 2010 - 11:53 AM
Thanks for guiding. You are right, that files can be included using 'include' . My point is that what is the fastest method in YII to include files. Can we use 'import' to include files. The reason for it is, in documentation I had read that 'import' is faster than 'include' or 'require'.
If so then 'import' will be used in same manner as 'include', 'require' are used ?
Thanks in advance
If so then 'import' will be used in same manner as 'include', 'require' are used ?
Thanks in advance
#6
Posted 14 April 2010 - 12:49 PM
Blue Sapphire, on 14 April 2010 - 11:53 AM, said:
Thanks for guiding. You are right, that files can be included using 'include' . My point is that what is the fastest method in YII to include files. Can we use 'import' to include files. The reason for it is, in documentation I had read that 'import' is faster than 'include' or 'require'.
If so then 'import' will be used in same manner as 'include', 'require' are used ?
Thanks in advance
If so then 'import' will be used in same manner as 'include', 'require' are used ?
Thanks in advance
Import won't actually run the content of the file though, that's part of what makes it faster. It's essentially adding it to the autoloading list of files to check for classes (at least that's my understanding).
Dana Luther
Sr. Developer at Envisage International
D.H. Luther - Web Design & Development
Dana's Yii Blog
Extensions:
ChildrenRequiredValidator | ESitemap | EStrongPassword | ES3
Sr. Developer at Envisage International
D.H. Luther - Web Design & Development
Dana's Yii Blog
Extensions:
ChildrenRequiredValidator | ESitemap | EStrongPassword | ES3
#7
Posted 14 April 2010 - 01:58 PM
Blue Sapphire, on 14 April 2010 - 07:26 AM, said:
Hi!
Iam newbie to YII. Can some one guide me the fastest way to include '_header.php', '_footer.php' file in my main layout file labelled as 'main.php'.
Thanks in advance
Iam newbie to YII. Can some one guide me the fastest way to include '_header.php', '_footer.php' file in my main layout file labelled as 'main.php'.
Thanks in advance
Use renderPartial:
<?php echo $this->renderPartial('_header', array('title'=>'Yii Rock!')); ?>
<?php echo $content; ?>
<?php echo $this->renderPartial('_footer', array('title'=>'Copyright 2010','param2'=>'hi')); ?>
#8
Posted 15 April 2010 - 03:03 AM
You can't beat require()/include() if all you want to do is include some content. Anything else is more "expensive". Don't make the mistake and try to find a "Yii-ish" solution for everything. If your sub-view doesn't use parameters but only static content, why use render() or renderPartial()? It only wraps the require() call (see CBaseController.php::renderInternal()) and adds some output buffering. This will eat some valuable CPU time.
So if you want best performance for your apps, keep things easy and make use of PHP's powerful functions where applicable.
Above is IMHO, of course.
So if you want best performance for your apps, keep things easy and make use of PHP's powerful functions where applicable.
Above is IMHO, of course.
Share this topic:
Page 1 of 1

Help
















