Im currently trying to simply add a block to a custom Adminhtml module. i am able to display the content of the block but it renders right at the top of the page with a grey background, and then the standard magento layout with the design and menu renders directly underneath it.
im trying to do things in the correct fashion as to learn best practises and am following books and tutorials as well as the magento core but so far have been unable to add content correctly.
so far i have :
public function indexAction()
{
$this->loadLayout();
$this->_setTitle();
$main_block = new Invent_General_Block_Info();
echo $main_block->toHtml();
//$this->_addContent($main_block);
$this->renderLayout();
i can see the general way to do so in the Mage Core would be something like
/**
* Append customers block to content
*/
$this->_addContent(
$this->getLayout()->createBlock('adminhtml/customer', 'customer')
);
since i have already created the block $main_block it doesnt make sense to me to ->createBlock and so im not sure what to do from here.
any assistance is appreciated as usual. thanks!
I have found an answer that solved this problem.
of course it would come from Alan Storm. Thanks Alan. the thread is found here!
so to solve this, all i did was :
create a folder in app/design/adminhtml/mythemename/info.phtml
and then in my controller action i simply did :
$this->loadLayout();
$this->_setTitle();
$this->_addContent($this->getLayout()->createBlock('adminhtml/template')->setTemplate('shipment/info.phtml'));
$this->renderLayout();
and it works great.
Use this if its a static block you created through your CMS
/**
* Append customers block to content
*/
$this->_addContent(
$this->getLayout()
->createBlock('cms/block')
->setBlockId('{block_name}')
->toHtml()
);
Related
I'm trying to customize the rendering of the standard_end_of_body(), but I can't seem to find the proper function.
I found the abstract function in /lib/outputrenderers.php, but not the actual theme implementation. In the code it is mentioned that it should be in the theme renderer, so I checked into every renderer, as well as the themes mine is based in (bootstrap and Elegance), but so far, nada.
So I'm very much open to any suggestions!
Thanks
In /theme/yourtheme/renderers/php
add this
class theme_yourtheme_core_renderer extends core_renderer {
public function standard_end_of_body_html() {
// Optionally add the parent html.
$output = parent::standard_end_of_body_html();
$output .= 'my stuff';
return ($output);
}
alternatively, you can also add footer html to the setting additionalhtmlfooter
via site admin -> appearance -> additional html
or direct to /admin/settings.php?section=additionalhtml
I am trying to add the view action to my back office module page but i cannot display anything with the renderview() function. I can already display my list with renderList() and it's working well. I also tried renderForm() and it works well too but it seemz i can't get renderView() to display something.
public function renderView(){
if(!($config = $this->loadObject())){
return;
}
$data = Config::getDataForm(Tools::getValue('id_config'));
// var_dump($data);
$this->tpl_view_vars = array(
'id_config' => $data['id_config'],
'prix' => $data['prix'],
'hauteur' => $data['hauteur_passage']
);
return parent::renderView();
}
This is a pretty basic code. My getDataForm($id_config) is getting fields from database in an array so that i can display it. I can see the var_dump displaying for a short time before displaying the blank page with prestashop header and footer. I tried to see if i was doing something wrond by checking other AdminController such as AdminCartsController or AdminCustomersController but it seems that their renderView() function is more or less written the same way.
Thanks in advance for your help !
I manage to resolve this problem simply by adding a view tpl in /modules/mymodule/views/templates/admin/mymodule/helpers/view/.
I wrongly assumed that it didn't need to create a template file for the view action as it didn't need one for the list and form action. After searching through modules and admin files i managed to find that there were indeed a custom view.tpl for the view action.
The renderview() method lets you set up the variables you want to use in your view.tpl.
For more information on how it works, you can check AdminCustomersController to see how it is on the controller side and /adminxxxx/themes/default/template/controllers/customers/helpers/view/view.tpl to see how the template is written.
Feel free to edit or comment if you need more information
If you want to add a configuration page on your module, you'll have to add this function to your module :
public function getContent()
{
// return some html content
}
If you want to use a controller, then you'll have to create a Controller that extends ModuleAdminController and add it in the tabs of the back-office.
I want to develop a membership plugin under wordpress and for this I want to use zend framework 2.
Does anyone managed to create a wordpress plugin using zend framework 2?
I'm new to zf and I do not know how and where to start from.
I tried to start from zend skeleton application but got stuck at add_menu_pages and displaying a simple dashboard.
Can anyone give me some ideas or links.
Thanks!
Updated!
I managed to get this working! I just needed to use a PhpRenderer. For those who need a little more help here is how I did:
I created a class that manages all admin area. On class init I called a method that created menu pages( in this method simply add_menu_pages() and instead of callback_function I called a new method, manage_pages, that, wel... manages pages, but you can do it as you desire) and then I initiated the view, like this:
$this->view = new PhpRenderer();
$this->map = new Resolver\TemplateMapResolver(array(
'template_name' => 'template_path',
'template2_name'=> 'template2_path')); //this is for handling view templates a little easier
$this->resolver = new Resolver\TemplateMapResolver($this->map);
$this->view->setResolver($this->resolver);
$this->model = new ViewModel();
Further, in manage_pages method, for each page I have, I added its own template and variables I needed
$this->model->setTemplate('template_name');
$this->model->setVariable('variable_name', value);
As for displaying template, you just have to write this piece of code:
echo $this->view->render($this->model);
In the template files you can access variables using $this->variable_name
Also you can insert another template using $this->partial( 'template2_name', assoc_arrray_of_variables_to_be_passed_to_template ).
And this is it! If you have any questions, please let me know!
There is a wordpress plugin you can use, search "wopzen2" or "wordpress and zend framework 2 integration" on Google, with this solution, you can use the following code inside the php wordpress code:
global $wpzf2plugin;
$render=$wpzf2plugin->render('/application/index/contactform');
echo $render;
This code calls the contactform action, if you are familiar with zendframework I think you are going to understand it.
This plugin is dedicated to developers.
You can get a free version of the plugin via support center.
I hope this answer can be helpful for you
reference link:
Example codes
I'm assuming it's one of the app layout files - I want to write a hook in my mobile template to pull a different CMS homepage.
Edit: To clarify, I want to achieve having a different cms page pulled for the hompage of a mobile version of the store vs. the desktop version. Since you can only set one default CMS page in magento admin, seems like there needs to be some custom coding in the mobile template files.
One of the things I love about Magento is the ability to accomplish a lot of things, just by playing with layout files.
I'll refer to Alan Storm's image to illustrate how I accomplished this exact task without having to change code (I hope you don't mind Alan).
As you can see with the image above, the Full Action Name is cms_index_index. You can find this information with debugging tools, like Commerce Bug.
As we have the action name, we can change the layout files to point to a mobile-specific home page. In this method the mobile-specific home page is actually a static block.
Once you have set up your mobile-specific content, you can add the following to your mobile template local.xml file, to use this block for your home page:
<cms_index_index>
<block type="cms/block" name="cms_page"><action method="setBlockId"><block_id>mobile_home</block_id></action></block>
</cms_index_index>
In this case I have set up a mobile_home static block. It will use the same layout name as the desktop home page, but this has already been overridden in the mobile template.
This may not be the best way, but it doesn't involve code changes.
It's probably not as straight forward as you'd like, but here's how this works.
The request for the homepage is routed to the indexAction method of the Mage_Cms_IndexController class.
If you take a look at the indexAction method you can see Magento uses the renderPage method of the cms/page helper object to render the contents of the page
#File: app/code/core/Mage/Cms/controllers/IndexController.php
public function indexAction($coreRoute = null)
{
$pageId = Mage::getStoreConfig(Mage_Cms_Helper_Page::XML_PATH_HOME_PAGE);
if (!Mage::helper('cms/page')->renderPage($this, $pageId)) {
$this->_forward('defaultIndex');
}
}
The $pageId is pulled from Magento's system configuration, and is the URL identifier of the CMS page.
If you hop to the renderPage method
#File: app/code/core/Mage/Cms/Helper/Page.php
public function renderPage(Mage_Core_Controller_Front_Action $action, $pageId = null)
{
return $this->_renderPage($action, $pageId);
}
it wraps the call to the protected _renderPage method. If you hop to THAT method, the page loading code is the following portions.
#File: app/code/core/Mage/Cms/Helper/Page.php
protected function _renderPage(Mage_Core_Controller_Varien_Action $action, $pageId = null, $renderLayout = true)
{
$page = Mage::getSingleton('cms/page');
//...
if (!$page->load($pageId)) {
return false;
}
//...
}
This loads the CMS Page object for the homepage. Notice the model is a singleton, which means other code that instantes the singleton later will have the same page. After this, standard Magento page rendering happens. Possibly relevant to your interests, the content layout blocks end up looking like this
Meaning the block HTML for the CMS page is rendered by the following code in Mage_Cms_Block_Page
#File: app/code/core/Mage/Cms/Helper/Page.php
protected function _toHtml()
{
/* #var $helper Mage_Cms_Helper_Data */
$helper = Mage::helper('cms');
$processor = $helper->getPageTemplateProcessor();
$html = $processor->filter($this->getPage()->getContent());
$html = $this->getMessagesBlock()->toHtml() . $html;
return $html;
}
The getPage method instantiates the same singleton we mentioned above. The other code is what replaces CMS page {{...}} directives with their actual content.
If I was approaching this project, I'd consider a class rewrite for the Mage_Cms_Model_Page object that looks something like this.
public function load($id, $field=null)
{
if( ... is mobile site ... AND ... $id is for the home page ...)
{
$id = ... ID of the mobile site, hard coded or pulled from custom config ...;
}
return parent::load($id, $field);
}
There's also the cms_page_render event which fires after the page has loaded in the _renderPage method. You could try reloading the passed in page object with a different ID in the observer. You could also consider something in the model_load_after or model_load_before events — although that gets trickier to do since you can't directly change the ID.
For code that's not going to leave a single client's system, I usually opt for the rewrite these days, since it's quicker (less expensive for clients) and has less complications (i.e. getting at and changing the information you need) during development. The trade-off is a possible future conflict with someone else who's rewriting the class.
Your milage/philosophy may vary.
Good luck!
I'm trying to create a widget within the module and then load that widget from 'outside' of the module. More particularly I'm using user module written by someone else. I don't want to have a separate page for displaying a login form, therefore I tried to make a CPortlet/widget (confusion) displaying the login form. Basically, I've moved the code from LoginController into that widget. Then I try to display the widget on some random page by
<?php $this->widget('user.components.LoginForm'); ?>
However, I get an error
CWebApplication does not have a method named "encrypting".
in UserIdentity class in this line:
else if(Yii::app()->controller->module->encrypting($this->password)!==$user->password)
This happens, because I'm basically trying to execute this code within context of the app and not the module. Thus the "Yii::app()->controller->module" trick doesn't really work as expected.
What am I doing wrong:-\
Is there a better way to achieve this. I.e. display that login form in some other page, which is normally displayed by accessing login controller within user module (user/login) or is a widget the right way of doing it?
Thanks.
The quick solution
Ok, so I simply ended up doing
Yii::app()->getModule('user')->encrypting($this->password)
instead of
Yii::app()->controller->module->encrypting($this->password)
Notice that now the module must be called 'user' in the main config, but I think this allows for more flexibility. I.e. we're not bound to only use module functionality within the module.
Additional insight on displaying widget outside of the module scope
After playing more with it that's what I did. In the UserModule.php I've created a method
public static function id() {
return 'user';
}
Then everywhere where I need the module I use
Yii::app()->getModule(UserModule::id())->encrypting($this->password)
I don't like having many imports related to the module like:
'application.modules.user.models.*',
'application.modules.user.components.*',
Because we already have those imports in the UserModule.php:
public function init()
{
// this method is called when the module is being created
// you may place code here to customize the module or the application
// import the module-level models and components
$this->setImport(array(
'user.models.*',
'user.components.*',
));
}
Therefore whenever you know that some piece of functionality will be used outside of the module it's important to make sure the module is loaded. For example, in the LoginForm widget that I am trying to display NOT in one of the module controllers, I have this line of code:
$model = new UserLogin;
However, UserLogin is a model inside of the User module, and in order to be able to autoload this model we first have to make sure the module was initialised:
$module = Yii::app()->getModule(UserModule::id());
$model = new UserLogin;
I hope this will be helpful if you were stuck with the whole modules concept the way I was.
http://www.yiiframework.com/forum/index.php?/topic/6449-access-another-modules-model/ was useful but hard to find =)
You better move that encrypting() into a MyUserIdentiy class which extends CUserIdentity. Whatever the code you take to use, they putting the method in controller is a bad idea and as a result you cannot reuse that code.
The login form should still post to User/Login controller but I guess they use Yii's standard login code and you might want to modify it to use the MyUserIdentity.