Witam
Jak rozwiazac sprawe modulow ?
Chcialbym zrobic cos takiego jak w Joomli, zeby moc miec dodatkowe proste moduly wyswietlane w odpowiednich miejscach na stronie.
Znacie jakis latwy sposob ?
<?php $response->insert('right', $this->view->render('logon.phtml')); ?>
CREATE TABLE IF NOT EXISTS `block_positions` ( `id` int(11) NOT NULL AUTO_INCREMENT, `blockName` varchar(50) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=6 ; -- -- Zrzut danych tabeli `block_positions` -- INSERT INTO `block_positions` (`id`, `blockName`) VALUES (1, 'Left'), (2, 'Right'), (3, 'Top'), (4, 'Header'), (5, 'Footer');
CREATE TABLE IF NOT EXISTS `blocks` ( `id` int(11) NOT NULL AUTO_INCREMENT, `block_position_id` int(11) NOT NULL, `ClassFile` varchar(200) NOT NULL, `role` varchar(50) NOT NULL, `published` int(1) NOT NULL, `params` text NOT NULL, `ordering` int(11) NOT NULL DEFAULT '0', `block_title` varchar(200) NOT NULL, `show_title` int(1) NOT NULL DEFAULT '0', PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=5 ; -- -- Zrzut danych tabeli `blocks` -- INSERT INTO `blocks` (`id`, `block_position_id`, `ClassFile`, `role`, `published`, `params`, `ordering`, `block_title`, `show_title`) VALUES (1, 2, 'Profile_Block_Login', 'Guests', 1, '', 0, 'Logowanie', 1), (4, 3, 'Default_Block_Search', 'Quests', 1, '', 0, '', 0);
<?php class Zadoo_View_Helper_DrawBlock extends Zend_View_Helper_Abstract { public $params; public function __construct() { $front = Zend_Controller_Front::getInstance(); $modules = $front->getControllerDirectory(); { require_once 'Zend/View/Exception.php'; throw new Zend_View_Exception('DrawBlock helper depends on valid front controller instance'); } $request = $front->getRequest(); $response = $front->getResponse(); require_once 'Zend/View/Exception.php'; throw new Zend_View_Exception('DrawBlock view helper requires both a registered request and response object in the front controller instance'); } $auth = Zend_Auth::getInstance(); $this->params->request = clone $request; $this->params->response = clone $response; $this->params->dispatcher = clone $front->getDispatcher(); $this->params->defaultModule = $front->getDefaultModule(); $this->params->acl = Zend_Registry::get("ACL"); $this->params->user = $auth->getIdentity(); $this->db = Zend_Registry::get("db"); } { $blocks = $this->db->fetchAll(" SELECT b.* FROM blocks AS b LEFT JOIN block_positions AS bp ON b.block_position_id = bp.id WHERE bp.blockName = '$pos' AND b.published = 1 ORDER BY ordering ASC "); if($getCount) { } foreach($blocks as $block) { $xhtml .= $tags[0]; if($block->show_title == 1) { $xhtml .= '<h2>' . $block->block_title . '</h2>'; } $params = $this->params; $params->params = $block->params; $class = new $block->ClassFile(); $xhtml .= $class->drawBlock($params, $pos); $xhtml .= $tags[1]; } $xhtml .= '</div>'; return $xhtml; } }
<?php class Profile_Block_Login { public function __construct() { } public function drawBlock($params, $block) { if( ! Zend_Auth::getInstance()->hasIdentity() ) { return $this->drawLogin($params, $block); } else { return $this->drawLogout($params, $block); } } public function drawLogout($params, $block) { $user = $params->user; $html = ''; Witaj ' . $user->username . '</li> <li><a href="/profile/edit">Edytuj profil</a></li> <li><A href="/profile/logout" >Wyloguj się</a></li></ul></div>'; return $html; } public function drawLogin($params, $block) { $html = ''; <form action="/profile/login/" method="post"> Login: <input type="text" name="username" size="5" /> Haslo: <input type="password" name="password" size="5" /> <input type="submit" value="OK"> </form> <a href="/profile/forgot">Przypomnij haslo</a> <a href="/profile/register">Rejestracja</a> </div>'; return $html; } }