Set a link from navigation to redirect on index
This is an open discussion with 22 replies, filed under General.
Search
Sorry, I am not sure I understand what you mean. There are two places I can imagine you're asking about:
- Root page: You go to
http://www.yoursite.com/
and want to see one of the index pages or a special page you've created - Any page: You go to
http://www.yoursite.com/film/
and want to see an index of all entries of a section represented on that page, possibly with links to subpages likehttp://www.yoursite.com/film/item/your-film/
@phoque, sorry if I'm not being clear.
You access http://www.mysite.com/
and will redirect to, as sample: http://www.mysite.com/film
. So the site owner have a section like home
with one field listing (maybe a select) the navigation itens (/photo, /film, /about, /contact) and he can select and save.
The owner don't want have a Home Page, =/
Make sense?
How would you know what page to redirect the visitor to? Redirects can be easily handled in the .htaccess
file.
Ah I see, a way for your client to define what page he wants as his/her homepage.
I'd say a combination of a "dumb page", a custom DataSource and a Section using a static Select Box field.
First off, create a Section "Homepage" with a Select Box field. Preset all possible values in the Section editor. Then create a DataSource "Homepage Redirect", pulling from Section "Homepage" and attach it to a new page /home/
. Set the type of that page to index
.
Now comes the tricky part. You have to manipulate the DataSource PHP. Take a look into workspace/data-sources/
. You should see a file data.homepage.php
in there.
First, set the returnvalue of public function allowEditorToParse()
to false
to prevent Symphony from overwriting your changes.
Then, at the very bottom of public function grab(&$param_pool=NULL)
you need to insert something similar to
header("Location: " + $result->getChildrenByName('entry')->getChildrenByName('homepage')->getAttribute('handle')); die();
Mind you that code line is completely off the top of my head, I have no idea how your $result
variable will look like. You'll have to do a var_dump($result)
to find what exact part of the result you're looking for.
So what we've done here is take a regular DataSource that pulls from one of our Sections and have modified it to do something with the resulting XML before we're sending it to the XML-pool and before we're doing any XSLT with it. In our case, we're doing a redirect by sending a Location: x
header to the client.
Cool, I will try and back you. Thanks.
Hi @phoque, I'm trying like you told, but I don't have know how to continue: I have this code:
$result = new XMLElement($this->dsParamROOTELEMENT); var_dump($result);
And the dump is returning:
object(XMLElement)#21 (13) { ["_name:private"]=> string(13) "home-redirect" ["_value:private"]=> NULL ["_attributes:private"]=> array(0) { } ["_children:private"]=> array(0) { } ["_processingInstructions:private"]=> array(0) { } ["_dtd:private"]=> NULL ["_encoding:private"]=> string(5) "utf-8" ["_version:private"]=> string(3) "1.0" ["_elementStyle:private"]=> string(3) "xml" ["_includeHeader:private"]=> bool(false) ["_selfclosing:private"]=> bool(true) ["_allowEmptyAttributes:private"]=> bool(true) ["_placeValueAfterChildElements:private"]=> bool(false) }
And Title "Home", no errors so =)
And the ?debug is: http://beta.marciotoledo.com/?debug
The method, you show me getChildrenByName
is not being recognized.
Looks like you're fetching the content of $result
too soon. You have to do it right before the value is being returned:
var_dump($result); return $result;
Also please note that viewing the result of var_dump
is much more readable when viewing the HTML-sourcecode, not what your Browser is trying to render.
@phoque Perfect explain nice tip about HTML Source hehehe.
I will try, I updated my previous comment with ?debug url. It's running fine.
@phoque, here is the new dump of $result and below the php code I trying.
var_dump($result); header("Location: /" + $result->getChildrenByName('home-redirect')->getChildrenByName('entry')->getChildrenByName('redirect-to')->getChildrenByName('item')->getAttribute('handle')); die(); return $result;
Try something like:
foreach($result->getChildrenByName('entry') as $entry){ if($homepage = $entry->getChildrenByName('homepage')) { header("Location: " + $homepage->getAttribute('handle')); } }
Make sure it's $homepage == $entry
(double equals sign) or it'll probably always be true!
Hi @Lewis, thanks. But same error. I try change the 'homepage' to home-redirect, redirect-to, item, etc.. and nothing.
This stopped erros:
var_dump($result); foreach($result->getChildrenByName('entry') as $entry){ if($redirect = $entry->getChildrenByName('item')) { header("Location: /" + $redirect->getAttribute('handle')); echo ($redirect->getAttribute('handle')); } } die();
@nickdunn and @Lewis I don't know where the $homepage is defined.
But the redirect is not working yet, I don't understand how to allow the attribute, I don't know manipulate the xml using php. The $result is dumping here: http://beta.marciotoledo.com/
Need get the photo handle string and put on location redirect, I tested using header('Location: /photo'); die();
and works fine.
How I reach this node/attribute ?object(XMLElement)#35 (13) { ["_name:private"]=> string(4) "item" ["_value:private"]=> string(5) "Photo" ["_attributes:private"]=> array(1) { ["handle"]=> string(5) "photo" }
In this $result: http://beta.marciotoledo.com/
@phoque, do you have an idea? Thanks for all, I think is closer to run hehe
Marcio, I checked on the error above and getChildrenByName()
is actually getChildren()
. It also appears that you cannot chain these these methods (at least that is what some quick tests taught me). Also, it looks like you're using a select box; the following code should work:
foreach($result->getChildren('entry') as $entry){ foreach($entry->getChildren('redirect-to') as $parent) { foreach($parent->getChildren('item') as $item){ header("Location: " + $item->getAttribute('handle')); } } }
Let us know if that works, we'll get it right sooner or later :-)
Make sure it's $homepage == $entry (double equals sign) or it'll probably always be true!
Nick, I hate when I do that! It's often going back and forth between PHP and XSLT.
Comment #17 looks like link spam to me.
Update: what was comment #17 has now been removed. Lewis's comment does not look like spam to me. :-)
DavidOliver, =)
Lewis, thank you man!
It's finding the value correct, take a look a 'info' before Symphony Warning, but now new problem =/
And PHP is:
var_dump($result); echo ('<br />---<br />'); foreach($result->getChildren('entry') as $entry){ foreach($entry->getChildren('redirect-to') as $parent) { foreach($parent->getChildren('item') as $item){ echo ($item->getAttribute('handle')); header("Location: " + $item->getAttribute('handle')); } } } die(); return $result;
Create an account or sign in to comment.
It's possible? Have some Extension? Have some Field like Select to set on admin to redirect index to this page?
Sample:
Navigation (not hidden): Film, Photos, About, Contact
When access the index, redirect to one of these navigation selected in somewhere.
Thanks,