How to compare current_url with site_url in codeigniter? - codeigniter

I have used something like that-
<?php if(current_url() == site_url()): ?>
...
...
<?php endif; ?>
But it's not working. I think there's something that I missed.

If you simply want to check if you're on the homepage of your site try this:
<?php if(strcmp(uri_string(),'')==0) : ?>
We are on the home page.
<?php endif; ?>
This solution will still work regardless of whether the base url is set correctly or not, unlike comparing base_url() and current_url().
Ensure that you have loaded the url helper either in your constructor or via autoloading.

Related

Magento: Switch From Grid view To List View, Without Changing URL

I was wondering if you could guide me how to allow the user to select either list or grid view, without changing the URL of the catalog/category page.
I.e., the page is either www.example.com/category?mode=grid OR www.example.com/category?mode=list but I want to make it just www.example.com/category and show the grid view by default, with the list view being displayed without changing the URL.
I hope you can help
There is no tutorial I guess..you have to do your own code ..And its not a big deal .. Open your list.phtml file in app/design/frontend/default/YOURTHEME/template/catalog/product/
Here you can see, they separate two view mode like this,
<div class="category-products">
<?php echo $this->getToolbarHtml() ?>
<?php // List mode ?>
<?php if($this->getMode()!='grid'): ?>
<?php $_iterator = 0; ?>
<ol class="products-list" id="products-list">
<?php foreach ($_productCollection as $_product): ?>
..bla.. bla ...
And Grid mode:
<?php else: ?>
<?php // Grid Mode ?>
Here they check the mode like this
<?php if($this->getMode()!='grid'): ?>
Just remove this condition, so that you can load both views, so now just add new css class or id to separate both modes, and manage them by Js like onclik event or something like that ...

Show Product on Search Page - Magento 1.7

Currently I have a snippet of code that will forward a user to the product page if they search for a term and only 1 product is associated with that keyword.
<?php if($this->getResultCount() == 1): ?>
<?php $prodId = $this->_productCollection->getAllIds() ?>
<?php $singleProduct = Mage::getModel('catalog/product')->load($prodId) ?>
<?php header('Location: ' . $singleProduct->getProductUrl()) ?>
<?php exit; ?>
<?php elseif($this->getResultCount()): ?>
However, what I want to do now is actually serve up the product and all its details on the results page itself if its the only one with that tag/search term INSTEAD of redirecting to the product page. Im pretty new to php so please bear with me.
Block template is bad place for this. Good place - controller.
Maybe you need rewrite controller for this functionality.
For example/app/code/core/Mage/CatalogSearch/controllers/ResultController.php
In controller your code looks like:
$this->getResponse()->setRedirect($_product->getProductUrl());

Display image in order comment in magento

I have added a comment to order on checkout success page. The comment is path to an image file. I want to display the image there rather than its path.
I added the following code for adding the comment,
$order->setState('processing', 'invoiced', $img_path);
Is it possible if I send html of image and image is shown rather than path?
Create a custom module that extend app/design/adminhtml/default/default/template/sales/order/view/history.phtml
Change Line #71 from
<?php if ($_item->getComment()): ?>
<br/><?php echo $this->escapeHtml($_item->getComment(), array('b','br','strong','i','u')) ?>
<?php endif; ?>
To
<?php if ($_item->getComment()): ?>
<br/><?php echo $this->escapeHtml($_item->getComment(), array('b','br','strong','i','u', 'img')) ?>
<?php endif; ?>
(If you have any issues check the value of 'comment' in sales_flat_order_status_history db to see if it already escapeHtml)

How to internationalize metas such as title in view.yml?

I'd like to internationalize the strings of my view.yml, I can't find how to do this.
I have a solution that is bad, in my opinion:
metas:
title: <?php echo sfContext::getInstance()->getI18n()->__('TITLE'); ?>
I'd like to find a way to do it without calling "sfConfig::getInstance()". Is it possible?
Never ever use sfContext for I18n in Configuration-Files! In such a case use the setTitle function in the View (not the controller)
<?php $sf_response->setTitle(__('TITLE'));?>
Since include_title() does not translate what it finds in view.yml, I made this very simple function in my custom helper:
function include_translated_title($context)
{
$title = $context->getI18N()->__($context->getResponse()->getTitle());
echo content_tag('title', $title)."\n";
}
Then I use it in my layout.php files:
<head>
<?php include_http_metas() ?>
<?php include_metas() ?>
<?php include_translated_title($sf_context) ?>
This way, I can use translation keys in my view.yml
You can do this in your action instead:
$this->getResponse()->setTitle(sfContext::getInstance()->getI18n()->__('TITLE'));
I dont think there's a way around using sfContext. You might be able to do something like this by getting rid of the default <?php include_title() ?> in your layout/view and the using the template i18n format to internationalise it:
<title><?php echo __('TITLE') ?></title>

Is it possible to target just Simple Product from phtml template?

I see something like:
<?php if(!$_item->isComposite() && $_item->isSaleable()): ?>
and this
<?php if(!$_product->isGrouped()): ?>
But couldn't find a way to target only the Simple Product type in similar manner.
<?php if( $_product->getTypeId() == 'simple' ): ?>
As an alternative possibility you could assume a Simple product is on that is no other type.
<?php if (!$_item->isComposite() && !$_item->isSuper() && !$_item->isVirtual()): ?>
<!-- Simple type only -->
<?php endif; ?>
There is already a template file catalog/product/view/type/simple.phtml that only displays for Simple type products.
If that doesn't show in the right place for you look in layout/catalog.xml for <PRODUCT_TYPE_simple> to see how to make your own Simple-only template file.

Resources