Jump to content

Recommended Posts

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?

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.