ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Retrieving pages url from database?

January 19, 2008 6:24am

Subscribe [3]
  • #1 / Jan 19, 2008 6:24am

    H&O

    34 posts

    Hi,

    First of all: WOW, what a CMS and WOW, what an extremly supportive community. We’re using this cms for over a year now and haven’t had to post in the forums before!

    But now, we’ve got a little problem (not really an EE one 😉). We’re using pages and have created a livesearch function (ajax) that searches through them. To get the results of the livesearch function actualy link to the right article, we’ll have to retrieve the pages’ urls’. Using a template, we can retrieve a list of all url’s by using this code:

    <?
    
    global $DB;
    
    $query = $DB->query("SELECT site_pages FROM exp_sites WHERE site_id = '1'");
    
    $pages = unserialize($query->row['site_pages']);
    
    foreach($pages['uris'] as $entry_id => $value)
    {
    
    echo $entry_id.'
    ';
    echo $value.'
    ';
    
    }
    ?>

    But, since the livesearch has to be very fast, we’re using hand coded php to search trough the database (no ee-templates evolved). The question is: how can we bypass the ‘query’-function of the DB class and what does it do that makes the code not work when take it out?

  • #2 / Jan 20, 2008 11:05am

    Robin Sowell

    13255 posts

    😉  Glad you’re enjoying it - and congrats on figuring out how to collect the uris.  It took me a while to track them down the first time, and I’m pretty clued in as to where to look!

    IF I understand correctly- you’re using straight php to do this?  That’s why the database class functions don’t work.  They are EE classes.  To do it completely outside of EE, you’d need to do it straight php.  Might be able to include just the db class and then make use of its functions- but I haven’t tried.  What I’d do instead- make it an EE plugin and then stick it on a template.  (Might have to be a module if you need an action id- but it would be a tiny one.)

    Anyway- point being, if you want to use the EE functions in your php, you’ll need to include them in your script.  Otherwise- you’ll need to switch to pure php (see php docs).  That make any sense at all?

  • #3 / Jan 26, 2008 10:25am

    H&O

    34 posts

    Thanks for your reply Robin. Since we wanted to be the livesearch-script to be very fast, we had to do without including EE classes. After a little bit research, we were able to retrieve the uri of page X by using this code:

    <?
    
    //query to get uri's
    $q = "SELECT site_pages FROM exp_sites WHERE site_id = '1'";
    $temp = mysql_query($q) or die('Query failed:'.mysql_error());    
    
    $temp_array = mysql_fetch_assoc($temp);
    $temp_array2 = unserialize($temp_array['site_pages']);
    
    $array = $temp_array2['uris']; // array with uri's
    
    //print' a uri:
    echo $array[4];
    
    ?>
.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases