Passe the current URL on every page

A place to discuss development of the Xataface core.

Passe the current URL on every page

Postby brunettia » Thu Sep 23, 2010 8:22 am

Hello!

I've got a question. I want to make a button to possibly bookmark every page of the site.
I don't really know how can i start that.

It should work like this: Page-->button add to bookmark-->action with a form to put a personal title--> put the title and the url to the database.

So i have to have a variable wich changes on every page and then passe it with the action.

Sorry for my english ;)

And a big thanks!
brunettia
 
Posts: 3
Joined: Thu Sep 23, 2010 8:15 am

Re: Passe the current URL on every page

Postby shannah » Fri Sep 24, 2010 10:42 am

You don't need to store the current URL in a variable. You can use javascript to obtain the url.
Code: Select all
window.location.href


Just pass this back to your action.
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

Re: Passe the current URL on every page

Postby brunettia » Sat Sep 25, 2010 3:28 am

Hi Steve,

Thx for the answer, but i'm not sure i really understand. I can put javascript in url from actions.ini? How does that work exactly if my code is like this:
Code: Select all
[add_favoris]
    url="{$app->url('-action=add_favoris&cur_url=')}"


thanks a lot for your work
brunettia
 
Posts: 3
Joined: Thu Sep 23, 2010 8:15 am

Re: Passe the current URL on every page

Postby shannah » Mon Sep 27, 2010 9:59 am

You can get the current url in the actions.ini file with
Code: Select all
$this->url('')


But I might suggest getting the URL of the requesting page inside your actual action via the HTTP_REFERER environment variable. That might be a little cleaner.
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

Re: Passe the current URL on every page

Postby brunettia » Thu Sep 30, 2010 3:27 pm

Tank's it actually works with the HTTP REFERER and it was easy to do, i can me dumb :)

I've got an other question, not with the URL but it is with my bookmarks too.

I've got a list into the block__after_left_column, with my bookmarks. Every bookmark can be deleted. So i've got this in my ApplicationDelegate
Code: Select all
function block__after_left_column() {
        $auth = & Dataface_AuthenticationTool::getInstance();
        $user = & $auth->getLoggedInUser();
        if (!$user)
            return Dataface_PermissionsTool::NO_ACCESS();
        $id_account = $user->val('ID_Account');
        $favoris = df_get_records_array('Favoris', array());
        echo '<div style="width:120px; float:left; margin:20px; padding:10px; border:1px dotted #CCC">';
        echo '<p>Vos favoris</p>';

        for ($i = 0; $i < sizeof($favoris); $i++) {
            $fk_account = $favoris[$i]->val('fk_account');

            if ($fk_account == $id_account) {
                echo '<li><a href="' . $favoris[$i]->val('url') . '">' . ($favoris[$i]->getTitle()) . '</a>
                    <a onclick="' . $this->deleteFavoris($favoris[$i]->val('Id_favoris'), 0) . '"><img src="./images/delete.png" alt="delete_fav"align="right"/></a></li>';
            }
        }
        echo '</div>';
    }

The problem is that the function deleteFavoris is executed by default, in every page!! Dunno why. Can you explain me something i've missed ?

Once again, sorry for my english!

Thx dude!

Alan
brunettia
 
Posts: 3
Joined: Thu Sep 23, 2010 8:15 am

Re: Passe the current URL on every page

Postby shannah » Wed Oct 06, 2010 10:04 am

Looks like you're mixing up server side code with client side code. All PHP will be server side code. This means it is executed when the page is created and cannot specifically respond to any user events like "onclick". You have tried to assign the php deleteFavoris() method to an HTML onclick handler, which won't work. You can only attach javascript to onclick handlers.

-Steve
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm


Return to Xataface Developers

Who is online

Users browsing this forum: No registered users and 11 guests

cron
Powered by Dataface
© 2005-2007 Steve Hannah All rights reserved