0

I am creating a new module for the blog and stuck.

Requirement I have a list of blogs that I am showing at the following url i.e. magento.local/blogs It is working fine. Now, my requirement is when I click on the "Read More" link to read the blog details then I need to generate the URL i.e. http://magento.local/blogs/how-to-login-to-magento/

Currently, I am doing the following i.e. href="getUrl('blogs/', array('title' => $news->getTitle())) ?>"> Read More

The above code is generating the following link i.e. http://magento.local/blogs/index/index/title/how to login to magento

I know that getUrl is required module/controller/action as first parameter but again it is showing the 'title' parameter in the URL as well.

I hope I have provided enough information about my requirement. Looking for help over here or link to an article link that describes how to achieve the current requirements....

1 Answer 1

1

In the URL, you can see: http://magento.local/blogs/index/index/title/how So blogs is the module name, the first 'index' is your controller, the 2nd 'index' is your action and then it put parameter and value. That is the real request URL which Magento calls. If you want to format the URL as "http://magento.local/blogs/how-to-login-to-magento/", you will have to rewrite the module. You can check the core module for more information on how to rewrite URL. Here is a quick code that you can try:

$url_key = Mage::helper('blogs')->generateUrlKey($model->getTitle());
$request_path = 'blogs/' . $url_key;
$rewriteModel = Mage::getModel('core/url_rewrite');
$id_path = 'blogs/index/index/' . $model->getId();
$rewriteModel->setData('request_path', $request_path);
$rewriteModel->setData('target_path', 'blogs/index/index/id/'.$model->getId());
$rewriteModel->setData('store_id', $store_id);
$rewriteModel->setData('is_system', 0);
$rewriteModel->save();
1
  • I am new to Magento and couldn't understand where to put the code, would you please send me the link/example that "how core module rewrite URL"? In addition, is the above code used to generate the URL from blogs/index/index/id/1 to blogs/how-to-login-to-magento/ need more explanation. Anyways, thanx for your efforts... Commented Jul 22, 2014 at 4:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.