Skip to content

Instantly share code, notes, and snippets.

@acodesmith
Created November 24, 2014 17:55
Show Gist options
  • Save acodesmith/93d8d95388be404852a1 to your computer and use it in GitHub Desktop.
Save acodesmith/93d8d95388be404852a1 to your computer and use it in GitHub Desktop.
renderPartial every file in a certain view folder
<?php
//View Location to auto load all .php files
$viewLocation = 'admin/variantRules/options';
//PHP glob function will return array. If there is an error double check your path
foreach (glob( Yii::app()->basePath."/views/".$viewLocation."/*.php") as $filename)
{
//Render every partial and load data
$this->renderPartial('//'.$viewLocation.'/'. str_replace('.php', '', array_pop( explode('/',$filename) ) ), array() );
}
?>
@acodesmith
Copy link
Author

Heads up! This only works inside a controller. If you need this to be done in a widget or component you will need to tweak render method to just render, not renderPartial.

Yii 1!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment