Follow along with the video below to see how to install our site as a web app on your home screen.
Anmerkung: This feature may not be available in some browsers.
ich dachte zunächst an ein plugin.. aber irgendwie komme ich nicht drauf, wie ich an dieser stelle an den view komme.. ist nicht ganz einfach sich in die struktur des frameworks reinzuarbeiten![]()
Zend_Layout::getMvcInstance()->view
ist es glaub ich, zumindest so ähnlich![]()
Dann ist ein Plugin doch ideal, dort hast direkt Zugriff auf den Request und nen View kann man sich erstellen.ich versuche gerade breadcrumbs in meinem projekt zu integrieren..
...
wie würdet ihr sowas integrieren? es ist logischerweise für jede seite nötig.. und ich brauche an der stelle, an der ich die breadcrumbs erstelle zugriff auf das view und das request objekt..
Einfach dem Plugin nen __constructor geben in dem Du nen neuen View erstellst.ich dachte zunächst an ein plugin.. aber irgendwie komme ich nicht drauf, wie ich an dieser stelle an den view komme..
Das ist richtig, Plugins musst Du beim FrontController registrieren, entweder wie du es gemacht hast mit einer Instanz, oder per config File.Und was ist der unterschied zwischen einer "resource" und einem "plugin"? in der bootstrap klasse habe ich eine methode "registerPluginResource()" aber keine methode registerPlugin().. zum registrieren des plugins habe ich mir in der bootstrap jetzt erstmal ne instanz des front controllers geholt und lade das plugin über diesen...
...
resources.frontController.plugins.auth = "Project_Controller_Plugin_Auth"
resources.frontController.plugins.navi = "Project_Controller_Plugin_Navigation"
...
Nö, wieso dafür ist der Thread doch da.(ich hoffe meine fragen sind nicht allzu blöd)
<?php
/**
* {PROJECT} Application
*
* This file is part of {PROJECT}
* Copyright (c) {COPYRIGHT_YEAR} by {COPYRIGHT_BY}
* All rights reserved
*
* @category {PROJECT}
* @copyright Copyright (c) {COPYRIGHT_YEAR}, {COPYRIGHT_BY} ({WEBSITE})
* @author Daniel Schumann
* @license {LICENSE}
* @version $Id: $
*/
/**
* Project_Controller_Plugin_Layout
*
* @category {PROJECT}
* @package Library
* @subpackage Plugins
* @uses Zend_Layout_Controller_Plugin_Layout
* @copyright Copyright (c) {COPYRIGHT_YEAR}, {COPYRIGHT_BY} ({WEBSITE})
* @license {LICENSE}
*/
class Project_Controller_Plugin_Navigation extends Zend_Controller_Plugin_Abstract
{
/**
* View Object
* too modifies the Output later.
*
* @var Zend_View
*/
protected $_view = NULL;
/**
* Config object
* @var Zend_Config
*/
private $_config = NULL;
/**
* Request Object
* @var Zend_Controller_Request_Abstract
*/
protected $_request = NULL;
/**
* Store a new View Object in Class.
*
* @return void
*/
public function __construct()
{
// get a new View
if($this->_view === NULL) {
$this->_view = new Zend_View;
}
}
/**
* Handle the Proccess for Navigation Loading.
*
* @see Controller/Plugin/Zend_Controller_Plugin_Abstract#postDispatch($request)
* @return void
*/
public function postDispatch(Zend_Controller_Request_Abstract $_request)
{
// save request for other methods
$this->_request = $_request;
if($this->_request->getModuleName() == Zend_Registry::get(Project_Registry_LocalConfig::REGISTRY_KEY)->system->adminmodul) {
// gets the admin Menu
$this->_getAdminMenu();
} else {
// gets the module Menu
$this->_getModuleMenu();
}
// set config readonly
if($this->_config !== NULL) {
$this->_config->setReadOnly();
}
// store the Navigation in Registry
$this->_addRegistry(new Zend_Navigation($this->_config));
// store the Acl Object in Helper
if(Zend_Registry::isRegistered(Project_Registry_Acl::REGISTRY_KEY)) {
Zend_View_Helper_Navigation_HelperAbstract::setDefaultAcl(Zend_Registry::get(Project_Registry_Acl::REGISTRY_KEY));
}
// store a Role in Helper
$role = Zend_Auth::getInstance()->hasIdentity() ?
Zend_Auth::getInstance()->getIdentity()->role :
'guest';
Zend_View_Helper_Navigation_HelperAbstract::setDefaultRole($role);
// store the Translator in Helper
if(Zend_Registry::isRegistered(Project_Registry_Translate::REGISTRY_KEY)) {
$this->_view->getHelper('navigation')->setTranslator(Zend_Registry::get(Project_Registry_Translate::REGISTRY_KEY));
}
// set the Zend_View Paths for these partial
// @todo !monitoring after ever Zend Library Update!
$this->_view->addScriptPath(array(
implode(DS, array(
APP_DIR,
'views', 'scripts'
)),
implode(DS, array(
Zend_Controller_Front::getInstance()->getModuleDirectory($_request->getModuleName()),
'views', 'scripts')
)
));
// insert Navigation in the current Response object
$this->getResponse()->insert(Project_Layout_Navigation::REGISTRY_KEY, $this->_view->getHelper('navigation')->menu()->setPartial('partials/menu.phtml'));
}
/**
* Handle the Proccess too fetch all the Modules Menu,
* from Config File named "admin.xml"
*
* @return void
*/
protected function _getAdminMenu()
{
$modules = $this->_getModules();
foreach($modules AS $modulPath) {
$this->_addConfig(implode(DS, array($modulPath, 'configs', 'admin.xml')));
}
}
/**
* Handle the Proccess too fetch the Modules Menu,
* from Config File named "menu.xml"
*
* @return void
*/
protected function _getModuleMenu()
{
// reset config if error handler is initiate
$this->_config = NULL;
$modules = $this->_getModules($this->_request->getModuleName());
foreach($modules AS $modulPath) {
$this->_addConfig(implode(DS, array($modulPath, 'configs', 'menu.xml')));
}
}
/**
* Set Config Data with the Modification Option
*
* @param string $_path
* @return void
*/
protected function _setConfig($_path)
{
$this->_config = new Zend_Config_Xml($_path, 'nav', TRUE);
}
/**
* Adds Config too the existing by using Zend_Config::merge()
*
* @param string $_path
* @return void
*/
protected function _addConfig($_path)
{
if(!Zend_Loader::isReadable($_path)) {
return;
}
if($this->_config === NULL) {
$this->_setConfig($_path);
return;
}
$this->_config->merge(new Zend_Config_Xml($_path, 'nav'));
}
/**
* Set Data too the existing Registry Key,
* by using Zend_Config->merge().
*
* @param object $_data Zend_Navigation instance
* @return Project_Controller_Plugin_Navigation provides Fluent Interface
*/
protected function _setRegistry(Zend_Navigation $_data)
{
Zend_Registry::set(Project_Registry_Navigation::REGISTRY_KEY, $_data);
return $this;
}
/**
* Adds Data too the existing Registry Key,
* by using Zend_Config->merge().
*
* @param object $_data Zend_Navigation instance
* @return Project_Controller_Plugin_Navigation provides Fluent Interface
*/
protected function _addRegistry(Zend_Navigation $_data)
{
if(Zend_Registry::isRegistered(Project_Registry_Navigation::REGISTRY_KEY) == FALSE) {
return $this->_setRegistry($_data);
}
Zend_Registry::set(Project_Registry_Navigation::REGISTRY_KEY,
(object)array_merge(
(array)Zend_Registry::get(Project_Registry_Navigation::REGISTRY_KEY),
(array)$_data
)
);
return $this;
}
/**
* Fetch Module Paths
*
* @param NULL|string|array $_module if NULL fetch all Modules, or the defined Modules
* @return array
*/
private function _getModules($_module = NULL)
{
// check if is an array
if($_module !== NULL && !is_array($_module)) {
settype($_module, 'array');
}
// workaround too get the aktually modules path
$path = Zend_Controller_Front::getInstance()->getModuleDirectory($this->_request->getModuleName());
$path = explode(DS, $path); // covert too array
unset($path[count($path)-1]); // delete module Directory
$path = implode(DS, $path) . DS; // convert too string
$paths = array();
// fetch all modules Directorys
$iterator = new DirectoryIterator($path);
while($iterator->valid()) {
if(!$iterator->isDot()) {
if($_module === NULL || in_array($iterator->getFilename(), $_module, TRUE)) {
$paths[] = $path . $iterator->getFilename();
}
}
$iterator->next();
}
return (array)$paths;
}
}
<?php echo $this->layout()->{Project_Layout_Navigation::REGISTRY_KEY}; ?>
<?php // "partials/menu.phtml"
if(!empty($this->container)): ?>
<ul class="navigation_normal">
<?php foreach($this->container as $page): ?>
<li><?php echo $this->navigation()->menu()->htmlify($page); ?>
<?php if(is_array($page->pages) && !empty($page->pages)): ?>
<ul class="container_pages" id="<?php echo (empty($page->id) ? substr(md5($page->href), 0, 8) : $page->id); ?>">
<?php foreach($page->pages AS $subpage): ?>
<li><?php echo $this->navigation()->menu()->htmlify($subpage); ?></li><?php echo PHP_EOL; ?>
<?php endforeach; ?>
</ul>
<?php endif; ?>
</li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
Einfach dem Plugin nen __constructor geben in dem Du nen neuen View erstellst.

Das ist richtig, wenn man den Inhalt des erstellten Views nicht in das Respons Object integriert. Das tue ich im Hook als letztesDann gehen doch aber die Änderungen die man am View-Objekt gemacht hat verloren, oder?
Btw: Warum verwendest du denn nicht einfach den Breadcrumb-View-Helper?![]()
// insert Navigation in the current Response object
$this->getResponse()->insert(Project_Layout_Navigation::REGISTRY_KEY, $this->_view->getHelper('navigation')->menu()->setPartial('partials/menu.phtml'));
Resourcen werden bisher nur von Zend_Application definiert, und da ist die Resource eben da um ein Moduk (Db, Controller, Mail, View ...) zu konfigurieren.Und der Unterschied von Resourcen und Plugins, wird mir Ice nun warscheinlich wiedersprechen, aber ich sehe es so das Resourcen benötigte Dinge laden und Plugins zum manipulieren oder erweitern der Funktionen da sind.
jo, also es gibt niemals nie einen Grund manuell neu ein View-Objekt zu erzeugen, es seidenn man nutzt auch den View-Teil für MailsDann gehen doch aber die Änderungen die man am View-Objekt gemacht hat verloren, oder?![]()
genau das dachte ich mir, das in das Layout rein und gut ist.Btw: Warum verwendest du denn nicht einfach den Breadcrumb-View-Helper?![]()
Btw: Warum verwendest du denn nicht einfach den Breadcrumb-View-Helper?![]()
@all oder speziell an Ice
Gibt es einen Weg in der Bootstrap an den Request zu gelangen bzw. an das gerade angefragte Modul?
$router = new Zend_Controller_Router_Rewrite();
$router->route(new Zend_Controller_Request_Http());
$router = new Zend_Controller_Router_Rewrite();
// add routes
$request = $router->route(new Zend_Controller_Request_Http($_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"]));
var_dump($request)
$router = new Zend_Controller_Router_Rewrite();
$module = $router->route(new Zend_Controller_Request_Http())->getModuleName();
Du musst in dem Request aber noch dir URL einstellen und dem Router natürlich noch die RewriteRules hinzufügen, dann sollte es aber funktionieren.