getting the multilingual alias. - drupal_get_path_alias - path

I am trying to create a multilingual site the following code outputs my main menu, however the links are retained as english when the user switches languages. I am using i8ln and entity translate. The two nodes exist so how do I retrieve the link for the multilingual page? I thought drupal_get_path_alias() would work by switching in the language. Code below.
<ul id="main-menu">
<?php
foreach($main_menu as $index)
{
dsm($index);
$path = file_create_url($index['menu_icon']['path']);
$class = $index['attributes']['class'][0];
$current = "node/".$node->nid;
$lang_name = $language->language ;
$linky = drupal_get_path_alias($index['href'], $lang_name);
if ($current == $index['href']) {
$class .= " selected";
};
print '<li class="'.$class.'">
<img src="'.$path.'" alt="icon-rockfall" />
<a class="'.$class.' textlink" href="/'.$linky.'">'.$index['title'].'</a></li>';
}
?>
</ul>
</nav>
<?php endif; ?>

I had the same problem, I resolved it with the code below:
<?php
global $language;
$url = url('node/1', array('language' => $language));
?>
Use the global $language object available.

This works for me:
<?php
global $language;
$url_nodo = url('node/' . $id_nodo, array('language' => $language));
$url_path = drupal_get_path_alias($url_nodo);
?>

Related

How to open a embed movie from mydabase using PHP

This is a clone site I make like www.teensnow.com. That works pretty good, but I don't wont open the target page.And this case is www.xhamster.com. So I wont open a page my and embed the movies in that page! Please take a look on the script ?>
<?php
$coneta = mysql_connect('localhost','root','') or die(mysql_error());
$banco = mysql_select_db('database');
?>
this layer is the target where the thumbs stay
<div align="center" id="box">
<div align="center" id="carrosel" style="width: 90%">
<?php // here is the pagination
$totalthumbsperpage = 64;
$page = (isset($_GET['pagina'])) ? (int)$_GET['pagina'] : 1;
$begin = ($totalthumbsperpage * $page) - $totalthumbsperpage;
$sql = "SELECT * FROM rowname ORDER BY thumb DESC LIMIT $begin, $totalthumbsperpage";
$qr = mysql_query($sql) or die(mysql_error());
while($ln = mysql_fetch_assoc($qr)){
?>
here is where the thumbs is showing on a page. But like you can see, I have the url open in a new page, that's good. But that urls is out of site my site and I want open the movie embedded on a page my.
<a href="<?php echo $ln['url'];?><img src="<?php echo $ln['thumb'];?></a>
<?php
}
?>
</div>
<div align="center">
<?php
$sqlTotal = "SELECT thumb FROM rowname";
$qrTotal = mysql_query($sqlTotal) or die(mysql_error());
$numTotal = mysql_num_rows($qrTotal);
$totalPagina= ceil($numTotal/$totalthumbsperpage);
for($i = 1; $i <= $totalPagina; $i++){
if($i == $pagina)
echo $i";}?>
</div><br><br>
</body>
</html>

Zend Framework 2 two templates in one layout?

In each module in my application I'll have a main content section and a sidebar menu.
In my layout I have the following...
<div id="main" class="span8 listings">
<?php echo $this->content; ?>
</div>
<div id="sidebar" class="span4">
<?php echo $this->sidebar; ?>
</div>
My controllers all return a single ViewModel which specifies the content (see below) but how do I get it to also populate the sidebar?
public function detailsAction()
{
*some code to populate data*
$params = array('data' => $data);
$viewModel = new ViewModel($params);
$viewModel->setTemplate('school/school/details.phtml');
return $viewModel;
}
I've got a feeling I am doing something fundamentally wrong here.
You can include "sub templates" by using the partial view helper
<div id="main" class="span8 listings">
<?php echo $this->content; ?>
</div>
<div id="sidebar" class="span4">
<?php echo $this->partial('sidebar.phtml', array('params' => $this->params)); ?>
</div>
In a controller you could use view models nesting and the layout plugin:
public function fooAction()
{
// Sidebar content
$content = array(
'name' => 'John'
'lastname' => 'Doe'
);
// Create a model for the sidebar
$sideBarModel = new Zend\View\Model\ViewModel($content);
// Set the sidebar template
$sideBarModel->setTemplate('my-module/my-controller/sidebar');
// layout plugin returns the layout model instance
// First parameter must be a model instance
// and the second is the variable name you want to capture the content
$this->layout()->addChild($sideBarModel, 'sidebar');
// ...
}
Now you just echo the variable in the layout script:
<?php
// 'sidebar' here is the same passed as the second parameter to addChild() method
echo $this->sidebar;
?>
// Module.php add it is
use Zend\View\Model\ViewModel;
public function onBootstrap($e)
{
$app = $e->getParam('application');
$app->getEventManager()->attach('dispatch', array($this, 'setLayout'));
}
public function setLayout($e)
{
// IF only for this module
$matches = $e->getRouteMatch();
$controller = $matches->getParam('controller');
if (false === strpos($controller, __NAMESPACE__)) {
// not a controller from this module
return;
}
// END IF
// Set the layout template
$template = $e->getViewModel();
$footer = new ViewModel(array('article' => "Dranzers"));
$footer->setTemplate('album/album/footer');
$template->addChild($footer, 'sidebar');
}

opencart add more more brands link in 3rd level category

using this code
$sisters = array_slice($sisters, 0, 5);
in catalog/controller/module/category.php
I'm displaying only 5 sister categories. I'm having a trouble adding a link stating View More which should link their parent category underneath all sister categories having more than 5 entries.
Any suggestion to solve this?
<?php if ($child['children1']) { $j=0; ?>
<?php foreach ($child['children1'] as $child1) { $j++; ?>
<?php if($j>2) { ?><li class="level-2-cat-list-sub-cat">More...</li><?php break; } else { ?>
<li class="level-2-cat-list-sub-cat" id="<?php echo $i; ?>">
<?php echo strtolower(ucwords($child1['name1'])); ?>
</li>
<?php } ?>
<?php } ?>
<?php } ?>
Make the not on above .tpl file there $j was declared and if it was greater than 2 More... was printed with and anchor tag and ended with "break;" statement

Issues with sfDoctrinePager pagination

I am using sfDoctrinePager in my module. I search the table on one or more criteria. First time the result displayed is correct but after it if I click on page 2 or more it again gives me the whole resultset and my search resultset is lost.
I am facing this issue for the first time, even though I have been using sfDoctrinePager since a long time.
I get this Array from my search form
(
[field_type] => log_type
[field_value] => ABC
[is_active] => on
)
I send this array variable to my model:
$getQuery = $objMgr->getSearchQuery($request->getPostParameters());
** The query which runs in model is:
public function getSearchQuery($arrSearchValues)
{
$q = Doctrine_Query::create()
->select('u.*')
->from('SomsConfigValues u');
->where('u.deleted_at IS NULL');
if(isset($arrSearchValues['is_active']) && $arrSearchValues['is_active'] == 'on'){
$q->where('u.is_active = ?', 1);
}
if(isset($arrSearchValues['field_type']) && $arrSearchValues['field_type'] != ""){
$revertChg = ucwords(str_replace("_", " ", $arrSearchValues['field_type']));
$q->andWhere('u.field_type = ?', $revertChg);
}
if(isset($arrSearchValues['field_value']) && $arrSearchValues['field_value'] != ''){
$q->andWhere('u.field_type = ?', $arrSearchValues['field_value']);
}
return $q;
}
First time I get the perfect searched result, but second time (when I click on page 2 it gives me whole resultset).
My action is:
public function executeIndex(sfWebRequest $request)
{
$objMgr = AdminFactory::adminObject();
$getQuerys = $objMgr->getSearchQuery($request->getPostParameters());
$this->config_values = $getQuerys;
$this->pager = new sfDoctrinePager('configValues', sfConfig::get('app_max_row_display'));
$this->pager->setQuery($this->config_values);
$this->pager->setPage($request->getParameter('page', 1));
$this->pager->init();
}
The template where I am using this pagination is:
<div class="grid_footer">
<div style="padding:5px;">
<?php if(count($pager->getLinks())) : ?>
<div class="tableControl">
<div class="pagination_inner">
<?php if(!$pager->isFirstPage()){ ?>
<?php echo link_to1(image_tag('/images/first.png'), 'configValues/index?page='.$pager->getFirstPage()) ?>
<?php echo link_to1(image_tag('/images/previous.png'), 'configValues/index?page='.$pager->getPreviousPage()) ?>
<?php } ?>
<div class="numbers">
<?php if ($pager->haveToPaginate()): ?>
<?php $links = $pager->getLinks(); foreach ($links as $page): ?>
<?php echo ($page == $pager->getPage()) ? $page : link_to($page, 'configValues/index?page='.$page) ?>
<?php endforeach ?>
<?php endif ?>
</div>
<?php if(!$pager->isLastPage()){ ?>
<?php echo link_to1(image_tag('/images/next.png'), 'configValues/index?page='.$pager->getNextPage()) ?>
<?php echo link_to1(image_tag('/images/last.png'), 'configValues/index?page='.$pager->getLastPage()) ?>
<?php } ?>
</div>
</div>
<?php echo $pager->getNbResults() ?> results (page <?php echo $pager->getPage(); ?>/<?php echo count($pager->getLinks()); ?>)
<?php endif; ?>
</div>
</div>
I was having exactly the same problem. The only way around this I found is as you said, to store the query. Instead of using the session, create an attribute in the user to store this.
in the action class put something like...
$this->getUser()->setAttribute('searchQuery', $getQuery);
This value persists through the session, so you can retreive it using e.g.
$storedQuery = $this->getUser()->getAttribute('searchQuery');
You can view the User attributes via the config item on the dev toolbar.

How to get downloadable product links after successfull order

After a successfull order I would like to propose directly the downloadable URL for products buyer bought in the success.phtml file.
I wrote this piece of code to know product's values of the latest order:
// Get the latest Order ID
$order = Mage::getModel('sales/order')->load(Mage::getSingleton('checkout/session')->getLastOrderId());
// Get every products on the latest order
$items = $order->getAllItems();
// Loop the products
foreach ($items as $item){
$product = Mage::getModel('catalog/product')->setStoreId($order->getStoreId())->load($item->getProductId());
// HERE I NEED FUNCTION TO GET DOWNLOADABLE URL LINK
}
I found a solution, here it is:
First, create a new .phtml file in template/downloadable/ , I called mine downloadablelist.phtml
Then copy all of template/downloadable/customer/products/list.phtml in our new downloadablelist.phtml
This will give us a copy of the customer account my downloadable products list.
Call our block in success page :
<?php echo $this->getLayout()->createBlock('downloadable/customer_products_list')->setTemplate('downloadable/checkout/downloadablelist.phtml')->toHtml(); ?>
Now I cleaned up what I don't need from the product list. I removed the table and added a ul instead.
Next is to show only the products that are made from the last order.
<?php
$_items = $this->getItems();
$orderId = Mage::getSingleton('checkout/session')->getLastRealOrderId();
if(count($_items)):
$_group_id = Mage::helper('customer')->getCustomer()->getGroupId();
echo '<p><strong>'.$this->__('Downloadable products').' : </strong></p>'; ?>
<ul style="margin-left: 30px; list-style: disc;">
<?php foreach ($_items as $_item):
$itemOrderId = $_item->getPurchased()->getOrderIncrementId();
if($itemOrderId == $orderId) {?>
<li><?php echo $this->htmlEscape($_item->getPurchased()->getProductName()) ?> - <a href="<?php echo $this->getUrl('downloadable/download/link/', array('id' => $_item->getLinkHash(), '_secure' => true)) ?>" title="<?php echo Mage::helper('downloadable')->__('Start Download') ?>" <?php echo $this->getIsOpenInNewWindow()?'onclick="this.target=\'_blank\'"':''; ?>><?php echo $_item->getLinkTitle() ?></a></li>
<?php }
endforeach; ?>
</ul>
<?php endif; ?>
I changed the url the original downloadable file had to :
href="<?php echo $this->getUrl('downloadable/download/link/', array('id' => $_item->getLinkHash(), '_secure' => true)) ?>"
Thank you
This worked for me:
$links = Mage::getModel('downloadable/link_purchased_item')->getCollection()
->addFieldToFilter('order_item_id', $item->getId());
foreach ($links as $link) {
echo Mage::helper('downloadable')->__('download') .
$this->getUrl('downloadable/download/link',
array('id' => $link->getLinkHash(), '_store' => $order()->getStore(),
'_secure' => true, '_nosid' => true));
}

Resources