Using ajax

Permalink
I am working on a block that is using jquery ajax. Is there a standard spot to put the php file the ajax is calling. Would this go into tools? Do i have to hard code the path to the file or is there a php constant or variable of sorts i can use. And lastly. The page i'm calling with ajax i need to call the database. What file can i look at to figure out how to connect to the database.
Am i making sense please let me know if i need to explain better what i am tring to do. Thanks all for you help and this fantastic product.

elygen
 
synlag replied on at Permalink Reply
synlag
If this how-tohttp://www.concrete5.org/archive/help/documentation/developers/unde... doesn't help, you should specific more exactly what you want to do.
elygen replied on at Permalink Reply
elygen
Yes I have read that. And although helpful it does not answer what I'm looking for. Below i tried to explain it better. It's rather simple what i need i guess I'm just not explaining it right.

Basically I'm building a block. This block is using jquery ajax to validate a name. So jquery calls a php script. I have this script within my block in the tools folder. The php script jquery is calling requires a call to the database. All i want to know is how do i access the database using concrete. Instead of creating my own connection and using my own wrappers. I just need to know how to implement the concrete database functions into my own php script.

I did find
$db = Loader::db();

what file do i have to include to use this functionality.

Thanks for the reply. It's been days.
andrew replied on at Permalink Reply
andrew
Sorry...our restructing the site lately has created all kinds of 404s, unfortunately. This documentation is available here:

http://www.concrete5.org/index.php?cID=2919...

To answer your other question...if you link to the item in the tools/ directory correctly, you shouldn't have to call anything to be able to use $db = Loader::db(); It should already be available.

You'll want to use this method to access the file in your block's tools directory:

<?php
$uh = Loader::helper('concrete/urls'); 
$base = $uh->getBlockTypeToolsURL($bt);
$path = $base . '/your_file_name';
?>


Note: you do not need to include .php on the end of $path, and it's probably best that you don't. This will generate a URL similar to:

/index.php/tools/blocks/yourblock/your_file_name

And from within that file you should be able to access the database.

Does this help?
elygen replied on at Permalink Reply
elygen
That link you left brings me to a comment page.

I'm going to try out what you showed me and let you know how it turn out. Thanks for the help.

p.s. I have used a lot of cms's in my time and this one is fantastic. The ability to create my own blocks so easily is beyond any other product i have ever used.
andrew replied on at Permalink Reply
andrew
Let me know if you need anything... and thanks for the kudos!
elygen replied on at Permalink Reply
elygen
I asked in another post but have not gotten a reply. how do i change the order of pages in the sitemap?
LucasAnderson replied on at Permalink Best Answer Reply
LucasAnderson
you can drag pages between other pages to move their location

click and hold on the icon next to the page name in the sitemap, then drag it to it's new position.

you should see a line form between the two pages you are trying to move it to
elygen replied on at Permalink Reply
elygen
there is no icon and cant drag them. maybe a reinstall.
thanks
elygen replied on at Permalink Reply
elygen
I reinstalled and now it works. It was weird. no icons and no drag and drop. Well if this happens to anyone else REINSTALL!!
cnrx replied on at Permalink Reply
cnrx
Hi elygen,

I have the same issue (I think) but the page I'm calling via Ajax does not seem to be able to access concrete's structure.

Have you resolved this?
ceyhuncenger replied on at Permalink Reply
ceyhuncenger
<?php defined('C5_EXECUTE') or die(_("Access Denied."));
    Loader::model('user_list');
    $ul = new UserList();
    $list = $ul->get();
    foreach($list as $u){
        echo $u->getUserName().' '.date('M d, Y',$u->getLastOnline()).' <br />';
    }
?>


I think, if you use something like this in your_file.php under your block's tools directory, then you will be able to get some data.
ShadowDancer replied on at Permalink Reply
I'm having a similar problem.

my add.php file needs to access the database when a text box is updated, which I'm doing with JQuery in auto.js

where do I put the
<?php
$uh = Loader::helper('concrete/urls'); 
$base = $uh->getBlockTypeToolsURL($bt);
$path = $base . '/your_file_name';
?>


part? and how do I get access to this newly created
$path
variable in my auto.js file?

also if I hardcode the url to the tools directory the php file in tools returns "access denied"
JohntheFish replied on at Permalink Reply
JohntheFish
During an add, the block does not exist yet. So the easiest way to do ajax is with a tools file.

Have a look at my AJAX Lessons Howto and associated addon, the various methods available in different contexts are tested and demonstrated.
ShadowDancer replied on at Permalink Reply
aye I'm using a tools file in myblock/tools/myfile.php

the JQuery is successfully posting the value from the textbox in add.php to myfile.php but the tools url is hardcoded which is unwise if the block needs to be installed elsewhere. I need to find a way to pass the tool url to the JQuery script. And somehow resolve this access denied issue I get when myfile.php attempts to query the database.