Magento _getUrl call function is duplicating the url to my link - magento

I use the function _getUrl to link the top link I created in my custom module, but for some reason it duplicates the URL. For example, say I want it to link me to:
www.localhost.com/magento/sapna/account/index
instead, it shows:
www.localhost.com/magento/http://index/www.localhost.com/magentosapna/account/index
Here is my function:
const ROUTE_FORM = 'sapna/account/index';
/**
* Retrieve goomer/breeder registariion url
*
* #return string
*/
public function getLoginUrl(){
return $this->_getUrl(self::ROUTE_FORM, $this->getLoginUrlParams());
}
i'm doing in module/Helper/Data.php and i use getUrl it does not work
I wrote this in the Data.php helper file. Can anyone help? I have been through this so many times, but I do not see what is wrong.

Check your customer.xml file for the following :
<customer_logged_out>
<reference name="top.links">
<action method="addLink" translate="label title" module="customer">
<label>Log In</label>
<url helper="customer/getLoginUrl"/>
<title>Log In</title>
<prepare/>
<urlParams/>
<position>100</position>
</action>
</reference>
<remove name="reorder"></remove>
</customer_logged_out>
/* Use <prepare/> instead of <prepare>true</prepare> */
worked for me...!

Related

Magento second header

I have a Magento store with two separate headers. Let's say out of 20 pages 15 use header.phtml and 5 use headerGreen.phtml. I've already created my custom layout module however I can't seem to get the new header to appear on select pages. The new headerGreen.phtml file has been created as well. The issue lies when I try to call the new header in the newly created layout page.
<?php echo $this->getChildHtml('headerGreen') ?>
I dont think I've added it correctly to the local.xml and was hoping someone could help.
<default>
<reference name="header">
<block type="core/template" name="header" template="page/headerGreen.phtml" />
</reference>
</default>
The function getChildHtml is expecting you to send a name of a child in the layout as first parameter
app/code/core/Mage/Core/Block/Abstract.php defines it :
/**
* Retrieve child block HTML
*
* #param string $name
* #param boolean $useCache
* #param boolean $sorted
* #return string
*/
public function getChildHtml($name = '', $useCache = true, $sorted = false)
{
// the code is does not really matter here
}
So based on your layout you should actually do
<?php echo $this->getChildHtml('header') ?>
Because header is the name attribute in this xml node of your layout :
<block type="core/template" name="header" template="page/headerGreen.phtml" />
As said in the comments, your layout is also looking strange because you are actually telling that your new header is going to be a child of the current header.
Two thinks you can do :
Use the powerfulness of the action nodes :
<default>
<reference name="header">
<action method="setTemplate">
<template>page/headerGreen.phtml</template>
</action>
</reference>
</default>
Or redefine the whole header block
<default>
<reference name="root">
<block type="core/template" name="header" as="header" template="page/headerGreen.phtml" />
</reference>
</default>

where is this method doing in admin controller (Grid Serializer)?

<?php
class Excellence_Manager_Adminhtml_ManagerController extends Mage_Adminhtml_Controller_action
{
public function customerAction(){
$this->loadLayout();
$this->getLayout()->getBlock('customer.grid')
->setCustomers($this->getRequest()->getPost('customers', null));
$this->renderLayout();
}
I am following this grid serializer tute . I just can not understand where is this setCustomers coming from ?
Even in other tutes I saw that setClent(), setDog() etc. But where is get or it's not from the database either. not in the layout either I think. Please help thanks.
<manager_adminhtml_manager_customer>
<block type="core/text_list" name="root" output="toHtml">
<block type="manager/adminhtml_manager_edit_tab_grid" name="customer.grid"/>
<block type="adminhtml/widget_grid_serializer" name="grid_serializer">
<reference name="grid_serializer">
<action method="initSerializerBlock">
<grid_block_name>customer.grid</grid_block_name>
<data_callback>getSelectedCustomers</data_callback>
<hidden_input_name>links[customers]</hidden_input_name>
<reload_param_name>customers</reload_param_name>
</action>
<action method="addColumnInputName">
<input_name>position</input_name>
</action>
</reference>
</block>
</block>
I found it's not from hidden_input_name or reload_param_name.
__set() is run when writing data to inaccessible properties.
__get() is utilized for reading data from inaccessible properties.
Magento implements so called "Magic Methods" to set data in an object.
They implemented __set and __get which are called, when no method for e.g. setCustomers() is found, and use those methods to do setData('customers', "YOUR_VALUE");

Pager toolbar in custom module in magento

I use this tutorial and display products on the basis of multiple categories but now I am getting in issue is that the pager tool bar not working on that.
My block code is :
<reference name="content">
<block name="mymodule" type="mymodule/product_listcategories" template="catalog/product/list.phtml">
<action method="setCategories">
<ids>2,3,4</ids>
</action>
</block>
</reference>
I also add this code with above
<block type="catalog/product_list_toolbar" name="product_list_toolbar" template="catalog/product/list/toolbar.phtml">
<block type="page/html_pager" name="product_list_toolbar_pager"/>
</block>
<action method="setToolbarBlockName"><name>product_list_toolbar</name></action>
</block>
It display toolbar but the toolbar is not working (limit,orderby).
My block code is
class Mymodule_Block_Product_Listcategories extends Mage_Catalog_Block_Product_List
{
protected function _getProductCollection()
{
$this->_productCollection = Mage::getModel('catalog/product')->getCollection();
$this->_productCollection->addAttributeToSelect('*');
if($this->getCategories()!="")
$this->_productCollection->addCategoriesFilter($this->getCategories());
return $this->_productCollection;
}
}
}
Does anyone know where is the problem? I think I'm missing some code for the pager? Thanks in advance
After search so much i got a solution.I didn't know whether it right or wrong way but it solve my problem.On my block i create intance of
$cpBlock = $this->getLayout()->getBlockSingleton('Mage_Catalog_Block_Product_List_Toolbar');
and access the pager core function like $this->_itemPerPage = $cpBlock->getLimit(); .In the above code itemperpage is the total no of items to be displayed on listing page.This code work if you create custom module and extend you block from list block.Thanks

Unable to render custom block template

I am using magento 1.7 and i have create custom widget block but some reason i am unable to render template i don't know why please give right solution and what is the problem with my code
if i return string code from _toHtml then its showing code but through phtml template file i am unable to render anything
block\slider.php
<?php
class XXXX_Slider_Block_Slider extends Mage_Core_Block_Template
{
/**
* Constructor. Set template.
*/
protected function _construct()
{
parent::_construct();
$this->setTemplate('slider/slider.phtml');
}
protected function _toHtml()
{
return parent::_toHtml();
}
}
and this is my slider/slider.phtml
slider is executed
and here is following my cms.xml
<?xml version="1.0"?>
<!--
/**
* Magento
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE_AFL.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license#magentocommerce.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade Magento to newer
* versions in the future. If you wish to customize Magento for your
* needs please refer to http://www.magentocommerce.com for more information.
*
* #category design
* #package base_default
* #copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
* #license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
*/
-->
<layout version="0.1.0">
<!--
Default layout, loads most of the pages
-->
<default>
<reference name="footer">
<block type="cms/block" name="cms_footer_links" before="footer_links">
<!--
The content of this block is taken from the database by its block_id.
You can manage it in admin CMS -> Static Blocks
-->
<action method="setBlockId"><block_id>footer_links</block_id></action>
</block>
</reference>
</default>
<cms_page translate="label">
<label>CMS Pages (All)</label>
<reference name="content">
<block type="slider/slider" name="easyshop.slider" template="slider/slider.phtml"/>
<block type="core/template" name="page_content_heading" template="cms/content_heading.phtml"/>
<block type="page/html_wrapper" name="cms.wrapper" translate="label">
<label>CMS Content Wrapper</label>
<action method="setElementClass"><value>std</value></action>
<block type="cms/page" name="cms_page"/>
</block>
</reference>
</cms_page>
<cms_index_index translate="label">
<label>CMS Home Page</label>
<remove name="cms_page" />
</cms_index_index>
<cms_index_defaultindex>
<remove name="right"/>
<remove name="left"/>
<reference name="root">
<action method="setTemplate"><template>page/1column.phtml</template></action>
</reference>
<reference name="content">
<block type="core/template" name="default_home_page" template="cms/default/home.phtml"/>
</reference>
</cms_index_defaultindex>
<cms_index_noroute translate="label">
<label>CMS No-Route Page</label>
</cms_index_noroute>
<cms_index_defaultnoroute>
<remove name="right"/>
<remove name="left"/>
<reference name="root">
<action method="setTemplate"><template>page/1column.phtml</template></action>
</reference>
<reference name="content">
<block type="core/template" name="default_no_route" template="cms/default/no-route.phtml"/>
</reference>
</cms_index_defaultnoroute>
</layout>
Please if you think question need more improvement then you can edit but please don't do unnecessary down vote this is my problem i am sharing here
Why do you extend your block from Mage_Core_Block_Abstract? Abstract class has no property $_template and your _toHtml() method does not implement template output. You need to extend from Mage_Core_Block_Template class.
Magento has several block types. You can find good list in this answer.

Add a calendar in Magento frontend

How can I add a calendar popup in the Magento frontend for a custom form?
Just add this code in your indexAction():
$this->loadLayout();
$blockCal = $this->getLayout()->createBlock(
'Mage_Core_Block_Html_Calendar',
'html_calendar',
array('template' => 'page/js/calendar.phtml')
);
$this->getLayout()->getBlock('content')->append($blockCal);
$headBlock = $this->getLayout()->getBlock('head');
$headBlock->addJs('calendar/calendar.js');
$headBlock->addJs('calendar/lang/calendar-en.js');
$headBlock->addJs('calendar/calendar-setup.js');
you can also define it in a layout file like this:
<reference name="head">
<action method="addItem"><type>js_css</type><name>calendar/calendar-win2k-1.css</name><params/><!--<if/><condition>can_load_calendar_js</condition>--></action>
<action method="addItem"><type>js</type><name>calendar/calendar.js</name><!--<params/><if/><condition>can_load_calendar_js</condition>--></action>
<action method="addItem"><type>js</type><name>calendar/calendar-setup.js</name><!--<params/><if/><condition>can_load_calendar_js</condition>--></action>
</reference>

Resources