gumbygreen123 Posted January 12, 2010 Share Posted January 12, 2010 As I've been using view partials I've realized that partials can only be used in the same (or perhaps a sub directory) directory that the script or layout is being read from. Is there a way to change the partial directory in Zend Framework? Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/188254-zf-changing-view-partial-path/ Share on other sites More sharing options...
gumbygreen123 Posted January 14, 2010 Author Share Posted January 14, 2010 Ok, so a couple days later and it seems that the partial path is the same as the layout path. There is probably a way to add additional layout paths but I don't really want to do that. The reason why I asked this question in the first place was to see if I could place general layouts in one folder and sub layouts in the same folders and locations as normal view script files. That way I could still utilize those script files that didn't seem to be doing anything after I discovered Zend_Layout. So, now I've decided to place the layout files directly in the 'scripts' folder and from there call the various scripts as partials to that layout. In the master layout I call the partials automatically with a string generated in the controller. In the controller I create an action helper that parses the URI and uses that information to determine the content partial that should be called. Below is the action helper (I'm not great with regex so there is a better way to do this and there is probably a better way to do this anyway using the Zend_Framework URI parser. Any insights on this would be helpful!): class Action_Helper_PartialEngine extends Zend_Controller_Action_Helper_Abstract { public function direct() { // Parse the uri to determine the current page. $pieces = explode('/',$_SERVER['REQUEST_URI']); // Determine the folder. $folder = ($pieces[1]) ? $pieces[1].'/': 'index/'; // Determine the file. // If the second piece has a dash in it, remove the dash and capitalize the first letter after the dash. if($pieces[2]){ $morePieces = explode('-',$pieces[2]); $i = 1; foreach($morePieces as $piece){ $file .= ($i > 1) ? ucfirst($piece): $piece; $i++; } $file .= '.phtml'; }else{ $file = 'index.phtml'; } // Return the correct path. return $folder.$file; } } Then in my controller I add the following code: class IndexController extends Zend_Controller_Action { public function init() { $this->view->partialName = $this->_helper->partialEngine(); } ... (actions etc.) } ...And in the master layout, where I want to call the partial I add this code: <?php echo $this->partial($this->partialName,$this->partialArray); ?> Any other insights on this would be helpful.. What do you all do? Quote Link to comment https://forums.phpfreaks.com/topic/188254-zf-changing-view-partial-path/#findComment-995086 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.