<![CDATA[ Retrieve ID of a modSymLink - My Forums]]> https://forums.modx.com/thread/?thread=45095 <![CDATA[Re: Retrieve ID of a modSymLink]]> https://forums.modx.com/thread/45095/retrieve-id-of-a-modsymlink#dis-post-475749
$_GET[$modx->getOption('request_param_id')]
when friendly urls are not being used.]]>
opengeek Aug 23, 2013, 10:27 PM https://forums.modx.com/thread/45095/retrieve-id-of-a-modsymlink#dis-post-475749
<![CDATA[Re: Retrieve ID of a modSymLink]]> https://forums.modx.com/thread/45095/retrieve-id-of-a-modsymlink#dis-post-475734
I wanted to set the System Setting 'symlink_merge_fields' to 'No' because it made everything a lot simpler in terms of guaranteeing nothing was overwritten with content drawn from the SymLink. I could list all the exceptions (being every single field in a TV rich template), but then if I ever added another field and forgot to add it to that list, strange behaviour may start to creep in.

I wanted the SymLink be IDENTICAL to the Target with the only difference being a correct bread crumb based on the location of the SymLink or Target in the structure. Hence I needed the SymLink ID to bait the BreadCrumb extra properly.

Big thanks to opengeek who supplied the building blocks of this snippet code in a few different places in the forums. The following placed into a snippet will correctly return the ID of the current resource if you have Friendly URLs switched on.

<?php
$uri = $_GET[$modx->getOption('request_param_alias')];
$resourceId = 0;
if (array_key_exists($uri, $modx->aliasMap)) {
    $resourceId = $modx->aliasMap[$uri];
};

return $resourceId;


If you're not using friendly URLs, try switching $_GET[$modx->getOption('request_param_alias')] for $_GET['q'] (untested but may work based on comments I've seen).

MODX - so many ways to achieve any given thing. Love it!]]>
jcdm Aug 23, 2013, 04:19 PM https://forums.modx.com/thread/45095/retrieve-id-of-a-modsymlink#dis-post-475734
<![CDATA[Re: Retrieve ID of a modSymLink]]> https://forums.modx.com/thread/45095/retrieve-id-of-a-modsymlink#dis-post-259576
the code is below

$id= $modx->resource->get(’id’);

$c = $modx->newQuery(’modResource’);
$c->select(’content’);
$c->where(array(’id’=>$id));
$c->prepare();
$c->stmt->execute();
$symlinkId = $c->stmt->fetchColumn();
$c->stmt->closeCursor();

if(is_numeric($symlinkId) && !empty($symlinkId))
{
return intval($symlinkId);
}

This may help, I think it still needs a bit of work, but it does return the symlink Id]]>
paulk May 06, 2011, 07:29 AM https://forums.modx.com/thread/45095/retrieve-id-of-a-modsymlink#dis-post-259576
<![CDATA[Re: Retrieve ID of a modSymLink]]> https://forums.modx.com/thread/45095/retrieve-id-of-a-modsymlink#dis-post-259575 http://bugs.modx.com/browse/MODX-2355

(I hope I did that right!)]]>
sushi Sep 22, 2010, 05:53 PM https://forums.modx.com/thread/45095/retrieve-id-of-a-modsymlink#dis-post-259575
<![CDATA[Re: Retrieve ID of a modSymLink]]> https://forums.modx.com/thread/45095/retrieve-id-of-a-modsymlink#dis-post-259574 Quote from: sushi at Sep 22, 2010, 02:11 PM

When viewing a resource of type modSymLink, the [[*id]] returns the ID of the original resource (as you would expect).

Is it possible to retrieve the ID of the modSymLink itself?
At the current time there is not a way to do this (that I can think of). I would love to hear ideas on how to achieve this before implementing a specific approach. Would you care to enter a ticket for this and maybe we can get some proposals and find the best way to accomplish this in a future release.]]>
opengeek Sep 22, 2010, 09:19 AM https://forums.modx.com/thread/45095/retrieve-id-of-a-modsymlink#dis-post-259574
<![CDATA[Retrieve ID of a modSymLink]]> https://forums.modx.com/thread/45095/retrieve-id-of-a-modsymlink#dis-post-259573
When viewing a resource of type modSymLink, the [[*id]] returns the ID of the original resource (as you would expect).

Is it possible to retrieve the ID of the modSymLink itself?

Thanks!]]>
sushi Sep 22, 2010, 09:11 AM https://forums.modx.com/thread/45095/retrieve-id-of-a-modsymlink#dis-post-259573