Jump to:

22996 Posts in 11844 Topics by 2828 members

General Questions

SilverStripe Forums » General Questions » Inserting an ?php include into ss

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 662 Views
  • wilsonStaff
    Avatar
    Community Member
    142 Posts

    Inserting an ?php include into ss Link to this post

    Hi to all, in my quest for the perfect GoogleMap module (which i havent found yet), i decided to give it a try and build one using a php module i bought on the Internet, AZStore. It does about what i want minus some bits.

    Problem is that documentation for AZStore is null. The owner says to put this into my template

    <?php
    include "locator/index.php";
    ?>

    As Wilr aptly mentionned, you cant run that into .ss template. So we tried this :

    => into mysite/code/PageMap3.php

    class PageMap3_Controller extends ContentController {
    . . .
    public function Locator() {
    include 'locator/index.php';
    return "Something";
    }
    . . .
    }

    then

    => in themes/mytheme/templates/PageMap3.ss

    $Locator

    - - -

    The "Something"; part is the key as Wilr says. But to replace with what?

    - - -

    Any other suggestions? The other solution is an <iframe> which i am not too keen using.

    Thanks!

  • swaiba
    Avatar
    Forum Moderator
    1769 Posts

    Re: Inserting an ?php include into ss Link to this post

    my guess is that the "include" is actually outputting something, so in order to use it with silverstipe template engine you'll need to buffer the output into a variable and then return that... http://php.net/manual/en/book.outcontrol.php

    Note this will cause problems if you want to include more than one map I think - based on gut insticnt - I have to ask what is wrong with Uncle Cheese's mappable - it's ACE!

  • wilsonStaff
    Avatar
    Community Member
    142 Posts

    Re: Inserting an ?php include into ss Link to this post

    Hi Swaiba, first, i am not using Mappable.

    Lets go thru this step by step.

    ==> into PageMap3.ss

    $Locator

    ==> into PageMap3.php

    function Locator() {
          include 'locator/index.php';
          return $output;
       }

    ==> into locator/index.php

    <?php
    include "locator.php"

    print $output;
    ?>

    ==> into locator.php

    <?php
    error_reporting('E_ALL');
    session_name('USESSID');
    session_start();

    include('config.php');
    include(DIR_FS_ROOT . 'func.php');
    include(DIR_FS_ROOT . 'init.php');
    include(DIR_FS_ROOT . 'class.template.php');
    include(DIR_FS_ROOT . 'class.paging.php');
    include(DIR_FS_ROOT . 'GoogleMap.php');

    $tpl = new FastTemplate(DIR_FS_ROOT . 'skins/' . SKIN_NAME);
    $tpl->no_strict();
    $tpl->define(array('main' => 'main.htm',
    'results' => 'results.htm',
    'results_no' => 'results_no.htm',
    'results_error' => 'results_error.htm',
    'form' => 'form.htm',
    'info' => 'info.htm',
    'info_phone' => 'info_phone.htm',
    'info_fax' => 'info_fax.htm',
    'info_email' => 'info_email.htm',
    'info_website' => 'info_website.htm',
    'info_number' => 'info_number.htm',
    'info_field1' => 'info_field1.htm',
    'info_field2' => 'info_field2.htm',
    'info_field3' => 'info_field3.htm',
    'nav' => 'nav.htm',
    'head' => 'head.htm'
    ));
    $tpl->define_dynamic('row', 'results');
    $tpl->define_dynamic('cell', 'results');

    $tpl->assign(array(
    'WWW_ROOT' => HTTP_SERVER . DIR_WS_ROOT,
    'SITE_TITLE' => 'Store Locator'
    ));

    if(!empty($_GET['cp'])) $cp = preg_replace('%[^a-z]%msi', '', $_GET['cp']);

    if(!empty($cp)) {
    if(file_exists($cp . '.php')) {
    include(DIR_FS_ROOT . $cp . '.php');
    } else {
    $output = 'Module not found';
    }
    } else {
    $tpl->assign('SITE_TITLE', '');
    include(DIR_FS_ROOT . 'def.php');
    }

    $tpl->assign(array('CONTENT_TEXT' => @$output));
    $tpl->parse('FORM', 'form');
    $az_locator_form = $tpl->fetch('FORM');
    $tpl->parse('PAGE', 'main');
    $output = $tpl->fetch('PAGE');
    ?>

    Look at last line, here is where retourn $output comes from.

    - - -

    Ive tried bypassing locator/index.php by including directly locator/locator.php

    ==> into PageMap3.php

    function Locator() {
          include 'locator/locator.php';
          return $output;
       }

    None of those works.....

    Thanks!

  • swaiba
    Avatar
    Forum Moderator
    1769 Posts

    Re: Inserting an ?php include into ss Link to this post

    Hey wilsonStaff,

    first, i am not using Mappable.

    I get it, but I was asking what's wrong with it, but if you don't want to answer that is fine...

    Lets go thru this step by step.

    I'm not going to intergrate it for you, maybe someone else will, but not me. I've given you a link that will provide you the information... basically the the "include" bit must output something if that is all that you have been "instructed" to do... so buffer it's output and return that.

    Best of luck!

  • wilsonStaff
    Avatar
    Community Member
    142 Posts

    Re: Inserting an ?php include into ss Link to this post

    Sorry Swaiba, english isnt my first language. I didnt get it was a question.

    Mappable?
    - Last time i checked (4 weeks ago) it was API V2 only. Now it says V3.
    - It didnt see it fullfilled all of my needs which are:
    - multiple (and numbered) markers
    - sidebars with list of points of sale
    - infowindow?
    - get directions?
    - search input fields?

    I didnt see because the demo page is quite spartan....

    - - -

    Now, i understand (and respect) that you dont want to point where the problem is.

    I'm not going to intergrate it for you, maybe someone else will, but not me.

    My post is about WHY its not working: is is SS related OR php module related...

  • swaiba
    Avatar
    Forum Moderator
    1769 Posts

    Re: Inserting an ?php include into ss Link to this post

    it does do a fair amount of the items on teh list, but you will need to do some hacking.

    and for the third time...

    the "include" is executing code and *probably* returning the rendered HTML to output

    however silverstripe wants the code returned in a string... so you need to butffer the output... try...

    function Locator() {

    ob_start();
    include 'locator/locator.php';
    $output = ob_get_contents();
    ob_end_clean();

    return $output;
    }

  • wilsonStaff
    Avatar
    Community Member
    142 Posts

    Re: Inserting an ?php include into ss Link to this post

    Hi Swaiba, first thanks for taking the time. Still not working.

    As a reference, the module itself worlks as seen as http://www.lebedouin.com/nouveau/locator/index.php?zip=&dist=1&mile=5&go=TROUVER

    - - -

    I could also end all this and use an <iframe> but would like to have it to work all under PHP.

  • wilsonStaff
    Avatar
    Community Member
    142 Posts

    Re: Inserting an ?php include into ss Link to this post

    Ok, finally it was a pathing problem.... As the folder i am developping the site into is named /nouveau, the whole process couldnt reach /locator.

    So putting this just after <? php of Page type solved the problem:

    $my_include_path = $_SERVER['DOCUMENT_ROOT'] . '/nouveau';
    set_include_path(get_include_path() . PATH_SEPARATOR .$my_include_path);

    Ill modify that once the site is live.

    - - -

    So up for now

    ==> into PageMap3.php
    function Locator() {
    include 'locator/index.php';
    return $output;
    }

    works fine and i can see the header of the map. But there is a consequence

    - - -

    Problem is that when i hit the SEARCH button, which is into a form, Silverstripe keep using /Sapphire for processing the form.

    The URL returned is this

    http://www.lebedouin.com/nouveau/sapphire/main.php?url=%2Fnouveau%2Fpoints-de-ventes2&zip=j3p+5n3&dist=1&mile=50&go=TROUVER

    while it should be this

    http://www.lebedouin.com/nouveau/locator/index.php?zip=H7L+4V4&dist=1&mile=5&go=TROUVER

    As i have multiple for on the site, i am not into modifying Sapphire nut more the script itself.

    This is the line is from the html table that contains the SEARCH BOTTOM:

    <form action="{LINK_ACTION}" onsubmit="return checkForm(this)">{HIDDEN_FIELDS}

    and that action is defined here

    'LINK_ACTION' => $_SERVER['PHP_SELF'], //href_link(basename($_SERVER['PHP_SELF']), ''),

    How to have to look into /locator instead of Sapphire?

    Thansk!

    662 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.