Page 1 of 1

Passe the current URL on every page

PostPosted: Thu Sep 23, 2010 8:22 am
by brunettia
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!

Re: Passe the current URL on every page

PostPosted: Fri Sep 24, 2010 10:42 am
by shannah
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.

Re: Passe the current URL on every page

PostPosted: Sat Sep 25, 2010 3:28 am
by brunettia
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

Re: Passe the current URL on every page

PostPosted: Mon Sep 27, 2010 9:59 am
by shannah
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.

Re: Passe the current URL on every page

PostPosted: Thu Sep 30, 2010 3:27 pm
by brunettia
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

Re: Passe the current URL on every page

PostPosted: Wed Oct 06, 2010 10:04 am
by shannah
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