Remove controller name from url for my custom module in Magento - php

I have created my own module. In that, I used IndexController. So the URL for me looks like http://192.168.1.25/upload/index.php/capsync/index/api.
I want to shorten the URL like http://192.168.1.25/upload/index.php/capsync/api.
I want to remove controller name. I tried in the config.xml file, but it shows a 404 error. I don't know how to fix this. Any ideas?

Try Magento rewrite functionality..
Open config.xml and add below code. It will make URL http://192.168.1.25/module/index/index/id/5 --> http://192.168.1.25/module/id/5 like this. Change Rule according to your need.
<global>
<rewrite>
<fancy_url>
<from><![CDATA[/module\/(.*)/]]></from>
<to><![CDATA[module/index/index/id/$1/]]></to>
<complete>1</complete>
</fancy_url>
</rewrite>
...

The most common solution for this is to divide your endpoint info different controller-files. In your example, you could change name from IndexController.php to ApiController.php and the method name from ApiAction() to IndexAction().

The code which works for me is as follows.
<global>
<rewrite>
<fancy_url>
<from><![CDATA[/capsync\/(.*)/]]></from>
<to><![CDATA[/capsync/index/$1/]]></to>
<complete>1</complete>
</fancy_url>
</rewrite>

Related

making Url user friendly in magento

This is my custom module url http://192.168.1.18/upload/index.php/capsync/
I want to call the next action from the controller apiaction with this:
http://192.168.1.18/upload/index.php/capsync/index/api
but remove index in the url:
http://192.168.1.18/upload/index.php/capsync/api
My config.xml page
<rewrite>
<Livelids_Capsync>
<from><![CDATA[#^capsync/index/api/#]]></from>
<to><![CDATA[api]]></to>
<complete>1</complete>
</Livelids_Capsync>
</rewrite>
In Magento, router will parse your URL as follows:
http://yoursite.com/[frontName]/[actionControllerName]/[actionMethod]/
In your case, For URL : http://192.168.1.18/upload/index.php/capsync/index/api
frontName :: capsync
actionControllerName :: indexController
actionMethod :: apiAction
Above is exactly what you want that is next action in the controller which would be 'apiAction'
Similarly, if you want URL : http://192.168.1.18/upload/index.php/capsync/api
Then your actionControllerName will turn to another controller(apiController) & action(indexAction by default) altogether which is what I don't think you want.
Let me know if you don't get this. Thanks! :)

Magento: Check if product is already in cart

Using magento for my shopping cart system. I have mini cart on top menu, when I added product it will show product title with price in mini cart. Currently have product quantity edit link but I need quantity box in mini cart to update quantity with ajax. I have followed this link http://ceckoslab.com/magento/magento-check-if-product-is-in-cart/, but getting following error
Fatal error: Class 'Mage_Smartview_Helper_Data' not found in /app/Mage.php on line 547
can anyone help me to resolve above error ?
When Magento is trying to look to Mage_Somemodule_ instead of your own module, it does means that it did not found your own file or your own module.
Three possible reasons :
Your module is not recognized at all, maybe something is wrong in your module definition
Something is wrong/mistyped in your config.xml
Something is wrong/mistyped in your class name
Be sure you have everything right from the tutorial and/or copy paste your code here so we can help further
In this case the two xml are wrong in the way that it should not ignore case sensitivity
CeckosLab_SmartView.xml
<?xml version="1.0"?>
<config>
<modules>
<CeckosLab_SmartView>
<active>true</active>
<codePool>local</codePool>
</CeckosLab_SmartView >
</modules>
</config>
config.xml
<?xml version="1.0"?>
<config>
<modules>
<CeckosLab_SmartView>
<version>1.0.0</version>
</CeckosLab_SmartView>
</modules>
<global>
<helpers>
<smartview>
<class>CeckosLab_SmartView_Helper</class>
</smartview>
</helpers>
</global>
</config>
please check it the Answer of stackoverflow
Click Here
In this link check this answer with 20 votes
Please check the releasenotes:
It will help you guide how to solve this issue
If your helper error contains Mage_ before your module, it means your helper is either not defined or defined incorrectly in your module's xml or you are calling it incorrectly.
If it is defined correctly this should work:
Mage::helper('smartview')->doSomething();
or try:
Mage::helper('ceckoslab_smartview')->doSomething();
Also, make sure you clear the cache as xml is cached heavily.
Hope this helps
Make enrty in config.xml
<global>
......
<helpers>
<test>
<class>Module_Test_Helper</class>
</test>
</helpers>
......
</global>
Create a Data.php file inside Helper folder and write following code
<?php
class Module_Test_Helper_Data extends Mage_Core_Helper_Abstract
{
}
Thats it you need to do now if you call this code it will not throw any error:
<?php Mage::helper("test")->actionname(); ?>

Magento: How to write an extension with a block that overrides functionality and another new custom block?

I was in the middle of writing some code for a Magento website, and I feel like I'm at odds with what I am trying to accomplish.
I am trying to write an extension which inserts 2 blocks:
Hello_Catalog_Block_Category_View: which overrides the Mage_Catalog_Block_Category_View Block with some extra functionality.
Hello_Catalog_Block_Custom: which is a customised class I want to create for this extension
Here's what I have tried to write in the config.xml file:
<blocks>
<catalog>
<rewrite>
<category_view>Hello_Catalog_Block_Category_View</category_view>
</rewrite>
<class>
<custom>Hello_Catalog_Block_Custom</custom>
</class>
</catalog>
</blocks>
Obvously if I tried this code when I refresh the browser, this doesn't work because I must have initialised the custom block the wrong way.
Now if I tried to write in this fashion:
<blocks>
<catalog>
<rewrite>
<category_view>Hello_Catalog_Block_Category_View</category_view>
</rewrite>
<class>Hello_Catalog_Block</class>
</catalog>
</blocks>
Now when I refresh the browser, the templates for Catalog Category view don't get rendered and I get the feeling it gets overridden by <class>Hello_Catalog_Block</class>.
My question is, is there a way to write an extension that allows these 2 blocks to be used or together or would it just be a case where either you write an extension that overrides blocks or you write an extension that creates new blocks only, not both?
Thanks.
I think there's a disconnect between what you think a "custom block" will do and what they actually do. There's no way to just add something to config.xml and have the block show up on the page.
If you want to create a custom block for your module, the first step is to configure a new top level section under blocks
<blocks>
<hello_catalog>
<class>Hello_Catalog_Block</class>
</hello_catalog>
</blocks>
The <hello_catalog> node is you block's group name. When you use the above configuration, you're telling Magento
Hey Magento, if you see a block in the hello_catalog group, it's class name should start with Hello_Catalog_Block.
With the above in place, you'll be able to do things in Magento's layout update XML files (the XML files in app/design) like this
<block type="hello_catalog/custom" name="me_custom_block" />
The above XML is creating a block of type hello_catalog/custom. That's a block in the hello_catalog group, with its class name being custom. Magento will translate this into the full class name Hello_Catalog_Block_Custom (using the information from config.xml for the base name, and then lead-word-casing custom.

config.xml override results in cart not visible?

I am building a second add to cart button with a different redirect on a magento platform.
The tutorial I've used is self explainatory. See here
It works okey as the redirect is in place.
The thing is: The cart itself doesnt show its page (cart.phtml) anymore.
Any idea how to fix this? Or where the problem exists?
If I remove the code underneath the cart is back again, as the redirect isn't working anymore.
File : config.xml
<global>
<routers>
<checkout>
<rewrite>
<cart>
<to>mycheckout/cart</to>
<override_actions>true</override_actions>
<actions>
<add>
<to>mycheckout/cart/add</to>
</add>
</actions>
</cart>
</rewrite>
</checkout>
</routers>
</global>
Seems like your extension does not extend the cart controller that you are overwriting making it impossible to display the methods from original controller

How do I load the layout from admin module in magento

I am having a difficult time getting the MVC structure set up for an admin module I am building for Magento. What I am hoping to do is correctly set up the design/adminhtml/layout/ppr_extension.xml to control the content of the page. So far I am loading the phtml and scripts from the IndexController :
$this->loadLayout();
$this->_setActiveMenu('ppr_menu/first_page');
$this->_addContent($this->getLayout()->createBlock('adminhtml/template')->setTemplate('ppr/ppr_1.phtml'));
$loadSimple = $this->getLayout()->getBlock('head')->addJs('ppr/load.simple.js');
$this->_addJs($loadSimple);
$this->renderLayout();
I want to load this from the config xml but for some reason I can not get this work. I imagine it has something to do with my package structure but I can not see it!
The template file exists in design/adminhtml/default/MyPackage/ppr_1.phtml
I tried adding this to the code/local/MyPackage/PPR/etc/config.xml
<adminhtml>
<menu> ... </menu>
<layout>
<updates>
<ppr_extension>
<file>ppr_extension.xml</file>
</ppr_extension>
</updates>
</layout>
</adminhtml>
That extension xml is in design/adminhtml/default/default/layout/ppr_extension.xml
I tried many things in here like :
<?xml version="1.0"?>
<layout version="0.1.0">
<ppr_adminhtml_ppr_index>
<reference name="head">
<action method="addJs"><script>script.js</script></action>
</reference>
No matter what I put in there nothing seems to happen. What am I missing?
I tried moving the extension.xml to design/adminhtml/MyPackage/layout but that didnt work either. Thanks for any help.. me brain hurts!
This should be easier now that you're using Commerce Bug.
The first step to debugging a layout problem is to make sure that your layout xml file is being loaded. Go to the layout tab in Commerce Bug and click on the Package Layout link. Look for your custom XML there. If you don't see it that means your XML isn't being loaded, and you should concentrate on getting the right XML in your config.xml, and getting your file in the right location.
Also, consider that the there's no need to use layout xml at all. The Admin Console developers use it for the outer shell and for some of the magic widget features, but there's a lot of stuff in the admin that's just blocks added in controller actions, or blocks added in other blocks. There's no shame in using PHP to generate your block objects.

Categories