[symfony-users] Re: Accessing doctrine route object in layout.php

2009-04-10 Thread Campezzi

Hey Tom!

I understand what you're trying to do now! I'm not sure if there's a
way to do that, but I'll run some tests and let you know the results.

Meanwhile, an alternate solution would be to consider using partials
and/or components on your layout.php file. That way, you'll be able to
update parts of the layout which are outside the view area (on the
decoration part). That might also be a more elegant design choice,
thinking on the MVC pattern and on the code/design separation talks :)

Take a look at the chapter Inside the View Layer  Code Fragments
on the symfony book, you might get some ideas from there!




On Apr 9, 5:19 pm, Tom Haskins-Vaughan t...@templestreetmedia.com
wrote:
 Thanks Thiago.

 Essentially my problem is that I need access to the property object in 
 layout.php.

 I am using the doctine route class:

 property:
    url:     /:id/:action
    class:   sfDoctrineRoute
    options: { model: Property, type: object }
    param:   { module: property }
    requirements:
      id: \d+
      sf_method: [get]

 And I have no trouble accessing the property object from the routing and I 
 can use this in actions and templates. However, I cannot pass this object to 
 the layout.

 In the layout I need to know the property_id, property_name, etc but I have 
 no idea how to access them. I think you used to be able to in sf1.0.

 I thought about using a component, but I couldn't access the property object 
 from the route in a component either.

 I'm sure there must be something simple that I'm over looking, but I can't 
 put my finger on it.

 Anyone?

 Cheers,

 Tom

 - Start Original Message -
 Sent: Thu, 9 Apr 2009 08:00:55 -0700 (PDT)
 From: Campezzi campe...@gmail.com
 To: symfony users symfony-users@googlegroups.com
 Subject: [symfony-users] Re: Accessing doctrine route object in layout.php





  Hi Tom,

  I believe you can get access to the routing from the layout by using
  the $sf_context variable. $sf_context-getRouting() should return a
  sfRouting object (http://www.symfony-project.org/api/1_2/sfRouting).
  You can then use the getRoutes() method of this object in order to get
  access to a collection of sfRoute objects (http://www.symfony-
  project.org/api/1_2/sfRoute). I haven't tested this, but in theory it
  should give you access to what you want :)

  However, I'm not too sure if this is a good practice. Depending on
  what you want to achieve, it would be best to simply set different
  routing rules. For example, for the photos section you would have a
  routing rule like this:

  photos:
    url: /:id/photos.htm
    param: { module: property, action: photos }

  then on the actions for this module you can use the ID passed by the
  user to do whatever:

    public function executePhotos(sfWebRequest $request)
    {
     $this-image = $request-getParameter('id') .'.png';
    }

  and then obviously you could use this variable on the view:

  img src=. $image . /

  Hope to have helped!

  Best Regards,

  Thiago Campezzi

  On Apr 9, 12:09 am, Tom Haskins-Vaughan t...@templestreetmedia.com
  wrote:
   Hi,

   I have a website where the people are given a url from some off-line
   source. e.g.

   example.com/22

   I'm using the doctrine routing object for my routes.

   22 is the id of a property and needs to be included in the routing in
   order to see other parts of the property:

   example.com/22/photos.htm
   example.com/22/town-info.htm
   example.com/22/view-property.htm

   So in layout.php I'd like to have access to the route object, but I
   don't see a way of accessing the route object in the layout. Is there a 
   way?

   Thanks in advance.

   Tom

 - End Original Message -
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
symfony users group.
To post to this group, send email to symfony-users@googlegroups.com
To unsubscribe from this group, send email to 
symfony-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/symfony-users?hl=en
-~--~~~~--~~--~--~---



[symfony-users] Re: Accessing doctrine route object in layout.php

2009-04-10 Thread Tom Haskins-Vaughan

Thanks, Thiago.

I'll give a little more background below but here's what I have so far:

I have a component in layout.php which accesses the property as follows:

// in frontend/modules/property/actions/components.class.php

   public function executeNavigation()
   {
 $request = $this-getContext()-getRequest();
 $sign_id = $request-getParameter('id');
 $this-sign = Doctrine::getTable('Sign')-find($sign_id);

 $this-navigation = 
sfYaml::load(sfConfig::get('sf_root_dir').'/apps/frontend/config/navigation.yml');
   }

This way I can access the Property via the Sign object (see below) but I 
assume this requires a new database call.

Background:

This is a mini site for a real estate agent. It is essentially a 
brochure site for some properties. In order to access the site, you must 
have been directed here from somewhere else, either online or offline.

Each property has one or more physical signs, that are displayed as 
normal real estate signs; on the lawn, for example. Each sign has a 
unique URL, eg:

   For more info on this property go to example.com/44

On the website, 44 is the id of the Sign object. To display all the 
information I simply access the Sign via the route object in the 
preExecute method of the actions class:

   $this-sign = $this-getRequest()-getRoute()-getObject();
   $this-property = $this-sign-getProperty();

This all works fine. But I need to include the navigation only if the 
sign has an active property, so in _navigation.php I need to do:

   ?php if ($sign-hasActiveProperty()): ?
 // show navigation
   ?php endif; ?

This all works. I suppose my situation is unique in that I only have one 
module in the application, but it would be nice if I could access the 
route object from the component. Perhaps there's a way to achieve it 
with filters.

Cheers,

Tom





Campezzi wrote:
 Hey Tom!
 
 I understand what you're trying to do now! I'm not sure if there's a
 way to do that, but I'll run some tests and let you know the results.
 
 Meanwhile, an alternate solution would be to consider using partials
 and/or components on your layout.php file. That way, you'll be able to
 update parts of the layout which are outside the view area (on the
 decoration part). That might also be a more elegant design choice,
 thinking on the MVC pattern and on the code/design separation talks :)
 
 Take a look at the chapter Inside the View Layer  Code Fragments
 on the symfony book, you might get some ideas from there!
 
 
 
 
 On Apr 9, 5:19 pm, Tom Haskins-Vaughan t...@templestreetmedia.com
 wrote:
 Thanks Thiago.

 Essentially my problem is that I need access to the property object in 
 layout.php.

 I am using the doctine route class:

 property:
url: /:id/:action
class:   sfDoctrineRoute
options: { model: Property, type: object }
param:   { module: property }
requirements:
  id: \d+
  sf_method: [get]

 And I have no trouble accessing the property object from the routing and I 
 can use this in actions and templates. However, I cannot pass this object to 
 the layout.

 In the layout I need to know the property_id, property_name, etc but I have 
 no idea how to access them. I think you used to be able to in sf1.0.

 I thought about using a component, but I couldn't access the property object 
 from the route in a component either.

 I'm sure there must be something simple that I'm over looking, but I can't 
 put my finger on it.

 Anyone?

 Cheers,

 Tom

 - Start Original Message -
 Sent: Thu, 9 Apr 2009 08:00:55 -0700 (PDT)
 From: Campezzi campe...@gmail.com
 To: symfony users symfony-users@googlegroups.com
 Subject: [symfony-users] Re: Accessing doctrine route object in layout.php





 Hi Tom,
 I believe you can get access to the routing from the layout by using
 the $sf_context variable. $sf_context-getRouting() should return a
 sfRouting object (http://www.symfony-project.org/api/1_2/sfRouting).
 You can then use the getRoutes() method of this object in order to get
 access to a collection of sfRoute objects (http://www.symfony-
 project.org/api/1_2/sfRoute). I haven't tested this, but in theory it
 should give you access to what you want :)
 However, I'm not too sure if this is a good practice. Depending on
 what you want to achieve, it would be best to simply set different
 routing rules. For example, for the photos section you would have a
 routing rule like this:
 photos:
   url: /:id/photos.htm
   param: { module: property, action: photos }
 then on the actions for this module you can use the ID passed by the
 user to do whatever:
   public function executePhotos(sfWebRequest $request)
   {
$this-image = $request-getParameter('id') .'.png';
   }
 and then obviously you could use this variable on the view:
 img src=. $image . /
 Hope to have helped!
 Best Regards,
 Thiago Campezzi
 On Apr 9, 12:09 am, Tom Haskins-Vaughan t...@templestreetmedia.com
 wrote:
 Hi,
 I have a website where the people are given a url from

[symfony-users] Re: Accessing doctrine route object in layout.php

2009-04-09 Thread Campezzi

Hi Tom,

I believe you can get access to the routing from the layout by using
the $sf_context variable. $sf_context-getRouting() should return a
sfRouting object (http://www.symfony-project.org/api/1_2/sfRouting).
You can then use the getRoutes() method of this object in order to get
access to a collection of sfRoute objects (http://www.symfony-
project.org/api/1_2/sfRoute). I haven't tested this, but in theory it
should give you access to what you want :)

However, I'm not too sure if this is a good practice. Depending on
what you want to achieve, it would be best to simply set different
routing rules. For example, for the photos section you would have a
routing rule like this:

photos:
  url: /:id/photos.htm
  param: { module: property, action: photos }


then on the actions for this module you can use the ID passed by the
user to do whatever:

  public function executePhotos(sfWebRequest $request)
  {
$this-image = $request-getParameter('id') .'.png';
  }


and then obviously you could use this variable on the view:

img src=. $image . /


Hope to have helped!

Best Regards,

Thiago Campezzi





On Apr 9, 12:09 am, Tom Haskins-Vaughan t...@templestreetmedia.com
wrote:
 Hi,

 I have a website where the people are given a url from some off-line
 source. e.g.

 example.com/22

 I'm using the doctrine routing object for my routes.

 22 is the id of a property and needs to be included in the routing in
 order to see other parts of the property:

 example.com/22/photos.htm
 example.com/22/town-info.htm
 example.com/22/view-property.htm

 So in layout.php I'd like to have access to the route object, but I
 don't see a way of accessing the route object in the layout. Is there a way?

 Thanks in advance.

 Tom
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
symfony users group.
To post to this group, send email to symfony-users@googlegroups.com
To unsubscribe from this group, send email to 
symfony-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/symfony-users?hl=en
-~--~~~~--~~--~--~---