Hi,
Thanks in advance.
I have an interesting problem. My company uses a CMS called Stellent
which basically just outputs a whole heap of html (daily) which is
then served up by Apache. For this, and other reasons, I can't just
directly call a symfony controller. I can only embed the controller
into certain pages which then allows a region of a page to include the
symfony output. The relative URL will always be different. I just want
forms to post back to the same action/page.

I did some digging around in the symfony code and found that it uses
$_SERVER['PATH_INFO'] to work out the routes.
So I started some ugly hacking. I put this into the controller:
        sfContext::getInstance()->getRequest()-
>setRelativeUrlRoot( $relative_url . '?route=' );
This just appends a 'route' parameter to the current url, so this       -
        url_for('myModule/myAction?param1=param1value')
would produce this -
        "/current/relative/url/?route=/myModule/myAction/param1/param1value"
So that when the form submits, this hack allows symfony to know the
route.
When there is no 'route' parameter, the relative URL is used to map to
a route.

I had to create a custom rendering filter so that I could separate the
header delivery from content delivery.

So I include most of the controller code at the top of the page (in
order
to allow for http header delivery) -

<?php
define('SF_ROOT_DIR',    realpath(dirname(__FILE__).'/sf'));
define('SF_APP',         'myapp');
define('SF_ENVIRONMENT', 'dev');
define('SF_DEBUG',       true);
define('MY_NAMESPACE','myns');

require_once(SF_ROOT_DIR.DIRECTORY_SEPARATOR.'apps'.DIRECTORY_SEPARATOR.SF_APP.DIRECTORY_SEPARATOR.'config'.DIRECTORY_SEPARATOR.'config.php');

$url = parse_url($_SERVER['REQUEST_URI']);
$path = isset($_REQUEST['route']) ? $_REQUEST['route'] : $url['path'];

// symfony hack, manually set $_SERVER['PATH_INFO'] variable
// not sure why I had to put the namespace thing in here, did this a
few weeks back
if( strpos($path,'/'.MY_NAMESPACE.'/') !== false ) {
        $_SERVER['PATH_INFO'] = $path;
} else {
        $_SERVER['PATH_INFO'] = '/' . MY_NAMESPACE . (( strpos($path,'/',0) !
== false )?'/':'') . $path;
}

// this will make symfony prepend the current url and append the
'route' param to all outbound links, forms etc.
sfContext::getInstance()->getRequest()-
>setRelativeUrlRoot($url['path'] . '?route=' );

// make the request, nothing is output here due to the custom
rendering filter
sfContext::getInstance()->getController()->dispatch();

$response = sfContext::getInstance()->getResponse();

// should probably set layout to 'off' here to ensure no layout rather
than in view.yml

// send headers
if (method_exists($response, 'sendHttpHeaders'))
{
  $response->sendHttpHeaders();
}
?>

...HTML created by Stellent...

...and then include this line into a region within the page -
<?php $response->sendContent(); ?>



The custom rendering filter only sends output for AJAX requests (AJAX
requests use another normal controller), otherwise response output is
called manually.
This enabled the headers to be sent at the top of the page:
        $response->sendHttpHeaders();
and the content to be inserted into the page:
        $response->sendContent();

Basically I have two includes to achieve this. One at the top of the
page and one where I want the content.

This is just too hacky.
Is this even a correct approach to the problem?
Is there a better way?

I'll rephrase the entire problem:
I need to insert dynamic content created by symfony into a region of
an existing singular php page.
How do I do this?
Suggestions?

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"symfony users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/symfony-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to