I have a module that creates pages in Magento. Since I can't duplicate the functionality of the module in a CMS page, I want to convert the module to produce pages that use the CMS model for its page output. I was looking in the Controller and this code looks promising, but I not sure what I would change. Can anyone help me?
// Setup layout handles
$this->getLayout()->getUpdate()
->addHandle('default')
->addHandle('custompage_map');
$this->addActionLayoutHandles();
$this->loadLayoutUpdates();
$this->generateLayoutXml()->generateLayoutBlocks();
foreach (array('catalog/session', 'checkout/session') as $class_name) {
$storage = Mage::getSingleton($class_name);
if ($storage) {
$this->getLayout()->getMessagesBlock()->addMessages($storage->getMessages(true));
}
}
// Render our layout
$this->renderLayout();
}
Take a look #
/app/code/core/Mage/Cms/controllers/IndexController.php
Replace your controller method with
public function noRouteAction($coreRoute = null)
{
$pageId = {cms page key};
if (!Mage::helper('cms/page')->renderPage($this, $pageId)) {
$this->_forward('defaultNoRoute');
}
}
Related
I am using the Zend skeleton application.
I want to have a sub menu bar (via a template) injected underneath the default site wide menu bar, but I don't want to modify the site wide app settings, I'd like to just have it in the module.
Looking at examples it seems I would have to manually inject the menu bar template in each of my controller's actions and in every template where I want it to appear like this:
public function indexAction() {
$view = new ViewModel();
$subNavView = new ViewModel();
$subNavView->setTemplate('helpdesk/helpdesk/subNav');
$view->addChild($subNavView, 'subNav');
return $view;
}
public function someAction() {
$view = new ViewModel();
$subNavView = new ViewModel();
$subNavView->setTemplate('helpdesk/helpdesk/subNav');
$view->addChild($subNavView, 'subNav');
....do something add variables to $view....
return $view;
}
public function someOtherAction() {
$view = new ViewModel();
$subNavView = new ViewModel();
$subNavView->setTemplate('helpdesk/helpdesk/subNav');
$view->addChild($subNavView, 'subNav');
....do something add variables to $view....
return $view;
}
...etc
And the "echo $this->subNav" in every template.
Is this the right way to do this or is there a way to have my module automatically include this template for every page (without modifying anything outside of the individual module)?
I read the docs, but I'm still confused on how to achieve this or if this is even possible.
If you want to update the view model directly, you could also do that in onBootstratp of your Module class:
public function onBootstrap($e) {
$view = $e->getApplication()->getMvcEvent()->getViewModel();
$subNavView = new ViewModel();
$subNavView->setTemplate('helpdesk/helpdesk/subNav');
$view->addChild($subNavView, 'subNav');
}
And of course you already have something like this in your layout:
<?php echo $this->subNav; ?>
You could also consider using the standard partial view helper and setting the template path as a variable in your model from your Module.php like this:
public function onBootstrap($e) {
$viewModel = $e->getApplication()->getMvcEvent()->getViewModel();
$viewModel->subNav = 'application/navigation/subNav.phtml';
}
Then you modify your /module/Application/view/layout/layout.phtml something like this
<?php if ($this->subNav) {
echo $this->partial($this->subNav);
} ?>
The drawback to this idea is that then you have a view model variable which will show up in all your models. This can be annoying, for example, in json results.
Last idea, you might want to consider a navigation view helper. You could implement https://github.com/spiffyjr/spiffy-navigation if you don't want to build one from scratch.
If you solve it with a view helper, either custom or pre-existing package such as Spiffy Jr's, then you'd modify your layout so it uses the helper something like this, and all the logic is provided by the helper class:
<?php echo $this->navigationMenu(); ?>
All three ideas will unclutter your controllers and let your Module set up the subNav in a way that is relevant to it, such as which routes it is valid for, etc.
I am rendering a page with a lot of frames (XHR contentpanes via dojo). This is done through a request to IndexController which sets up regions 'header,left,right,center,footer' with the exception, that center is not filled in with contents. This in turn is set by calling PaneController in menu.onclick. Caveat; search engines indexing service does not get center region contents.. I wish to bypass AJAX loading of center, if user enters via /index/index.
Relevant snippets from IndexController:
class IndexController extends Zend_Controller_Action {
public function indexAction() {
$this->indexModel = $this->view->indexModel = new Application_Model_Index();
// Goal is to render "/pane/main/" action and capture the HTML
$this->view->mainPane = (string) $this->renderPaneMain();
return $this->render();
}
public function renderPaneMain() {
// ActionStack ?
// action() ?
return $HTML;
}
}
Relevant stuff in Pane
class PaneController extends Zend_Controller_Action {
public function preDispatch() {
// will only return a contentpane, dont render layout
if ($this->getRequest()->isXmlHttpRequest()) {
$this->_helper->layout()->disableLayout();
$this->view->doLayout = true;
}
}
public function mainAction() {
this.render("main.phtml");
}
public function init() {
$this->panesModel = new Application_Model_Panes();
$variant = $this->getRequest()->getParam('variant', '');
// routing variables need to be set, how?
if (empty($variant))
$this->_redirect('/');
}
}
Basically, i need the PaneController to _not render the global layout but call its .phtml view file, once it has been setup with relevant model entries and such.
Any ideas as to how I can achieve this in its most efficient form?
Very well, ill attach the workaround im using here
The forms and the fork-logic i have moved to the model that is coexisting with PanesController. For the IndexController, which will present the default Pane as inline HTML without AJAX - there is a couple of duplicated initializations going on.
So, IndexModel extends the PanesModel - without initializing it. In my index.phtml view (for Index action) i have following code to render the inline html from a pane.
in index controller
$this->view->model = new IndexModel(); // extends PanesModel
$this->view->model->setDefaultProperties($variant, $pagination, ...);
in index view:
$this->partial("panes/main/main.phtml", array("model", $this->model);
and from pane view:
<?php if($this->model->goThisDirection()): ?>
Switch 1 HTML contents
<?php endif; ?>
Caveat: I also had to not render any form of layout within the pane (dojox contentpanes allows for <script> and <style> tags) - and this ofc ripples to any other pane action of mine.
call controller to view i use this code..
i want to add "template/home/home" page in to iframe tag while calling controller to view.
how can i do?
class main_con extends Controller
{
function main_con()
{
parent::Controller();
// $this->freakauth_light->check('user');
$this->_container = $this->config->item('FAL_template_dir') . 'template/container';
$this->load->library('FAL_front', 'fal_front');
}
function index()
{
$data['redirect_page'] = 'template/home/home';
$this->load->vars($data);
$this->load->view($this->_container);
}
}
thank you in advance...
I'm not quite sure if I understand your problem but:
The iframe is in your view template right? So what you need to do is just print the content of your variable in the src attrib of the iframe.
I'm trying to add a link to one of my blocks to a specific action of one of my controllers. Looking through the class docs and googling didn't resolve something useful. (maybe I just used the wrong search queries).
My Controller has two actions:
indexAction() and exportAction()
Now, in one of my blocks I wand to add link to exportAction(). I've found the method addLink() but this doesn't work.
Maybe anyone knows how to do that ? Or could point me to the right resources on the net ?
Regards, Alex
Block Example:
<?php
class Polyvision_Tempest_Block_Adminhtml_View extends Mage_Adminhtml_Block_Template
{
public function __construct()
{
parent::__construct();
}
protected function _toHtml()
{
$html = "whatever";
return $html;
}
}
?>
Your question isn't clear/complete.
A block renders HTML, either through a phtml template or through PHP code. To add an HTML link, you just render a html anchor tag with an href
//via PHP
protected function _toHtml()
{
$html = 'My Link';
return $html;
}
//via phtml template
#your block
class Polyvision_Tempest_Block_Adminhtml_View extends Mage_Adminhtml_Block_Template
{
protected function _construct()
{
$this->setTemplate('path/to/from/template/folder/as/basetemplate.phtml');
}
}
#your template
My Link';
The addLink method is a special method that only applies to certain types of blocks. When you call it it add links information to the block's data properties. Then, it's _toHtml method or phtml template has been written such that it loops over the stored data to output links. It doesn't apply to general blocks, which is what makes your question confusing.
Hope that helps!
I am having trouble simply making multiple pages with CodeIgniter. For example, I am trying to make a simple About page with codeigniter. So I create an about.php controller and an about_view.php view file. However if I were to try and make a link from the home page to "http://miketrottman.com/about" it will go nowhere. I am sure I am fundamentally missing something but I have read and watched example videos I am just spinning my wheels on this project at this point. Here is my home.php controller, let me know if I should post any other code. My site is http://miketrottman.com. I am new to the CodeIgniter scene an any help is much appreciated!
home.php in Controller directory
'
class Home extends Controller {
function Home()
{
parent::Controller();
}
function index()
{
//Load Extensions
$this->load->database();
$this->load->library('session');
//Include these basics everytime the home page is loaded
$data['pageTitle'] = "Trottman's Blog";
$data['title'] = "Trottman's Blog Title";
$data['heading'] = "Trottman's Blog Heading";
//Load Proper CSS for users browser
$data['css'] = $this->getCSS();
//Load the Blog Model
$this->load->model('blog_model');
//Load the Blog Entries
$data['blog'] = $this->blog_model->getBlogEntries();
$data['blog_comments'] = $this->blog_model->getBlogCommentEntries();
//
//Load all of this information into the home_view Page
$this->load->view('home_view', $data);
}
function getCSS()
{
//Load user_agent library to pull user's browser information
$this->load->library('user_agent');
//Agent is now the users browser
$agent = $this->agent->browser();
//According to the users browser, this is what the CSS should be
if ($agent == 'Internet Explorer')
{
$cssFile = "ieStyle.css";
}
else
{
$cssFile = "style.css";
}
return $cssFile;
}
}?>
'
And I am dumb, my whole problem was I was trying to go to /about and what I should have been doing is http://miketrottman.com/index.php/about because I have yet to remove the index.php in my URIs.
So I guess, thanks Stack overflow for creating an outlet for my ignorance, perhaps others can learn from my mistake then!