<?xml version="1.0" encoding="UTF-8"?><rss
version="2.0"
xmlns:content="http://purl.org/rss/1.0/modules/content/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:atom="http://www.w3.org/2005/Atom"
xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
> <channel><title>Comments on: Snippet: Symfony User &#8211; Access the User Object</title> <atom:link href="http://erisds.co.uk/symfony/snippet-symfony-user-access-the-user-object/feed" rel="self" type="application/rss+xml" /><link>http://erisds.co.uk/symfony/snippet-symfony-user-access-the-user-object</link> <description>Web development, Symfony, Wordpress and general geekery</description> <lastBuildDate>Wed, 10 Mar 2010 10:22:19 +0000</lastBuildDate> <generator>http://wordpress.org/?v=2.9.1</generator> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <item><title>By: symfonybr :: Symfony - Snippet - Maneiras de acessar o objeto User</title><link>http://erisds.co.uk/symfony/snippet-symfony-user-access-the-user-object/comment-page-1#comment-413</link> <dc:creator>symfonybr :: Symfony - Snippet - Maneiras de acessar o objeto User</dc:creator> <pubDate>Tue, 03 Nov 2009 14:18:58 +0000</pubDate> <guid
isPermaLink="false">http://erisds.co.uk/?p=83#comment-413</guid> <description>[...] font: http://erisds.co.uk/symfony/snippet-symfony-user-access-the-user-object [...]</description> <content:encoded><![CDATA[<p>[...] font: <a
href="http://erisds.co.uk/symfony/snippet-symfony-user-access-the-user-object">http://erisds.co.uk/symfony/snippet-symfony-user-access-the-user-object</a> [...]</p> ]]></content:encoded> </item> <item><title>By: Arif</title><link>http://erisds.co.uk/symfony/snippet-symfony-user-access-the-user-object/comment-page-1#comment-398</link> <dc:creator>Arif</dc:creator> <pubDate>Fri, 16 Oct 2009 09:41:37 +0000</pubDate> <guid
isPermaLink="false">http://erisds.co.uk/?p=83#comment-398</guid> <description>Thanks, it&#039;s really very easy to understand , keep going on</description> <content:encoded><![CDATA[<p>Thanks, it&#8217;s really very easy to understand , keep going on</p> ]]></content:encoded> </item> <item><title>By: pfwd</title><link>http://erisds.co.uk/symfony/snippet-symfony-user-access-the-user-object/comment-page-1#comment-311</link> <dc:creator>pfwd</dc:creator> <pubDate>Sun, 09 Aug 2009 15:12:16 +0000</pubDate> <guid
isPermaLink="false">http://erisds.co.uk/?p=83#comment-311</guid> <description>Hi Jimmy,
I couldn&#039;t get the following to work in my action:&lt;code&gt;$this-&gt;getUser-&gt;getUserId();&lt;/code&gt;Even tho this worked:&lt;code&gt;$this-&gt;getUser-&gt;getUsername();&lt;/code&gt;I did manage to get all the fields (including the id ) by adding getGuardUser() like so:&lt;code&gt;$this-&gt;getUser()-&gt;getGuardUser()-&gt;getId();&lt;/code&gt;&lt;code&gt;$this-&gt;getUser()-&gt;getGuardUser()-&gt;getUsername();&lt;/code&gt;&lt;code&gt;$this-&gt;getUser()-&gt;getGuardUser()-&gt;getCreatedAt();&lt;/code&gt;This is a link to my source http://forum.symfony-project.org/index.php/m/75314/
Hope that helps</description> <content:encoded><![CDATA[<p>Hi Jimmy,<br
/> I couldn&#8217;t get the following to work in my action:</p><div
class="codecolorer-container text twitlight" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table
cellspacing="0" cellpadding="0"><tbody><tr><td
style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br
/></div></td><td><div
class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">$this-&gt;getUser-&gt;getUserId();</div></td></tr></tbody></table></div><p>Even tho this worked:</p><div
class="codecolorer-container text twitlight" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table
cellspacing="0" cellpadding="0"><tbody><tr><td
style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br
/></div></td><td><div
class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">$this-&gt;getUser-&gt;getUsername();</div></td></tr></tbody></table></div><p>I did manage to get all the fields (including the id ) by adding getGuardUser() like so:</p><div
class="codecolorer-container text twitlight" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table
cellspacing="0" cellpadding="0"><tbody><tr><td
style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br
/></div></td><td><div
class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">$this-&gt;getUser()-&gt;getGuardUser()-&gt;getId();</div></td></tr></tbody></table></div><div
class="codecolorer-container text twitlight" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table
cellspacing="0" cellpadding="0"><tbody><tr><td
style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br
/></div></td><td><div
class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">$this-&gt;getUser()-&gt;getGuardUser()-&gt;getUsername();</div></td></tr></tbody></table></div><div
class="codecolorer-container text twitlight" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table
cellspacing="0" cellpadding="0"><tbody><tr><td
style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br
/></div></td><td><div
class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">$this-&gt;getUser()-&gt;getGuardUser()-&gt;getCreatedAt();</div></td></tr></tbody></table></div><p>This is a link to my source <a
href="http://forum.symfony-project.org/index.php/m/75314/">http://forum.symfony-project.org/index.php/m/75314/</a><br
/> Hope that helps</p> ]]></content:encoded> </item> <item><title>By: ErisDS</title><link>http://erisds.co.uk/symfony/snippet-symfony-user-access-the-user-object/comment-page-1#comment-285</link> <dc:creator>ErisDS</dc:creator> <pubDate>Tue, 28 Jul 2009 21:24:10 +0000</pubDate> <guid
isPermaLink="false">http://erisds.co.uk/?p=83#comment-285</guid> <description>Hi Jimmy,&lt;kbd&gt;sfContext::getInstance()-&gt;getUser()-&gt;getId(); &lt;/kbd&gt;should work anywhere but the view, but is the ugly way to do it as Hugo explains above.In an action you can use &lt;kbd&gt;$this-&gt;getUser()-&gt;getId();&lt;/kbd&gt; and in a view it will be &lt;kbd&gt;$sf_user-&gt;getId();&lt;/kbd&gt;If you can&#039;t get it to work then get in touch with me via my contact form and we&#039;ll take a closer look.</description> <content:encoded><![CDATA[<p>Hi Jimmy,</p><p><kbd>sfContext::getInstance()->getUser()->getId(); </kbd>should work anywhere but the view, but is the ugly way to do it as Hugo explains above.</p><p>In an action you can use <kbd>$this->getUser()->getId();</kbd> and in a view it will be <kbd>$sf_user->getId();</kbd></p><p>If you can&#8217;t get it to work then get in touch with me via my contact form and we&#8217;ll take a closer look.</p> ]]></content:encoded> </item> <item><title>By: Jimmy</title><link>http://erisds.co.uk/symfony/snippet-symfony-user-access-the-user-object/comment-page-1#comment-275</link> <dc:creator>Jimmy</dc:creator> <pubDate>Tue, 28 Jul 2009 14:19:22 +0000</pubDate> <guid
isPermaLink="false">http://erisds.co.uk/?p=83#comment-275</guid> <description>Do you also now how to get the userID from a view, model, action etc?
I tried sfContext::getInstance()-&gt;getUserId(); and sfContext::getInstance()-&gt;getUser()-&gt;getId();..?Cheers, Jim</description> <content:encoded><![CDATA[<p>Do you also now how to get the userID from a view, model, action etc?<br
/> I tried sfContext::getInstance()-&gt;getUserId(); and sfContext::getInstance()-&gt;getUser()-&gt;getId();</p><p>..?</p><p>Cheers, Jim</p> ]]></content:encoded> </item> <item><title>By: ErisDS</title><link>http://erisds.co.uk/symfony/snippet-symfony-user-access-the-user-object/comment-page-1#comment-60</link> <dc:creator>ErisDS</dc:creator> <pubDate>Tue, 12 May 2009 02:01:28 +0000</pubDate> <guid
isPermaLink="false">http://erisds.co.uk/?p=83#comment-60</guid> <description>@hugo: Sorry for the delay in my reply, I&#039;m currently on holiday :) Thanks for your insights on this problem &amp; taking the time to share them here. I plan  update this post with your solution when I get home &amp; have some time to experiment with using this method for forms :)</description> <content:encoded><![CDATA[<p>@hugo: Sorry for the delay in my reply, I&#8217;m currently on holiday :) Thanks for your insights on this problem &#038; taking the time to share them here. I plan  update this post with your solution when I get home &#038; have some time to experiment with using this method for forms :)</p> ]]></content:encoded> </item> <item><title>By: Hugo</title><link>http://erisds.co.uk/symfony/snippet-symfony-user-access-the-user-object/comment-page-1#comment-37</link> <dc:creator>Hugo</dc:creator> <pubDate>Mon, 27 Apr 2009 11:11:51 +0000</pubDate> <guid
isPermaLink="false">http://erisds.co.uk/?p=83#comment-37</guid> <description>Retrieving a factory object (request, response, user,  cache...)  from the sfContext singleton is the ugly way as it relies on a string couple between classes. The ideal way to use the context in a model is to pass it explicitly with a setter like below :&lt;code lang=&quot;php&quot; tab_size=&quot;2&quot;&gt;
&lt; ?phpclass MyModelObject
{
private $user = null;public function setUser(sfUser $user)
{
$this-&gt;user = $user;
}public function save($conn = null)
{
$this-&gt;setUserId($this-&gt;user-&gt;getId());return parent::save($conn);
}
}
&lt;/code&gt;And in the action :&lt;code lang=&quot;php&quot; tab_size=&quot;2&quot;&gt;
public function executeAction(sfWebRequest $request)
{
$obj = new MyModelObject();
$obj-&gt;setUser($this-&gt;getUser());// You can access the context with $this-&gt;getContext();
}
&lt;/code&gt;++Hugo.</description> <content:encoded><![CDATA[<p>Retrieving a factory object (request, response, user,  cache&#8230;)  from the sfContext singleton is the ugly way as it relies on a string couple between classes. The ideal way to use the context in a model is to pass it explicitly with a setter like below :</p><div
class="codecolorer-container php twitlight" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table
cellspacing="0" cellpadding="0"><tbody><tr><td
style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br
/>2<br
/>3<br
/>4<br
/>5<br
/>6<br
/>7<br
/>8<br
/>9<br
/>10<br
/>11<br
/>12<br
/>13<br
/>14<br
/>15<br
/>16<br
/>17<br
/>18<br
/></div></td><td><div
class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span
style="color: #000000; font-weight: bold;">&lt;?php</span><br
/> <br
/> <span
style="color: #000000; font-weight: bold;">class</span> MyModelObject<br
/> <span
style="color: #009900;">&#123;</span><br
/> &nbsp; <span
style="color: #000000; font-weight: bold;">private</span> <span
style="color: #000088;">$user</span> <span
style="color: #339933;">=</span> <span
style="color: #009900; font-weight: bold;">null</span><span
style="color: #339933;">;</span><br
/> <br
/> &nbsp; <span
style="color: #000000; font-weight: bold;">public</span> <span
style="color: #000000; font-weight: bold;">function</span> setUser<span
style="color: #009900;">&#40;</span>sfUser <span
style="color: #000088;">$user</span><span
style="color: #009900;">&#41;</span><br
/> &nbsp; <span
style="color: #009900;">&#123;</span><br
/> &nbsp; &nbsp; <span
style="color: #000088;">$this</span><span
style="color: #339933;">-&gt;</span><span
style="color: #004000;">user</span> <span
style="color: #339933;">=</span> <span
style="color: #000088;">$user</span><span
style="color: #339933;">;</span><br
/> &nbsp; <span
style="color: #009900;">&#125;</span><br
/> <br
/> &nbsp; <span
style="color: #000000; font-weight: bold;">public</span> <span
style="color: #000000; font-weight: bold;">function</span> save<span
style="color: #009900;">&#40;</span><span
style="color: #000088;">$conn</span> <span
style="color: #339933;">=</span> <span
style="color: #009900; font-weight: bold;">null</span><span
style="color: #009900;">&#41;</span><br
/> &nbsp; <span
style="color: #009900;">&#123;</span><br
/> &nbsp; &nbsp; <span
style="color: #000088;">$this</span><span
style="color: #339933;">-&gt;</span><span
style="color: #004000;">setUserId</span><span
style="color: #009900;">&#40;</span><span
style="color: #000088;">$this</span><span
style="color: #339933;">-&gt;</span><span
style="color: #004000;">user</span><span
style="color: #339933;">-&gt;</span><span
style="color: #004000;">getId</span><span
style="color: #009900;">&#40;</span><span
style="color: #009900;">&#41;</span><span
style="color: #009900;">&#41;</span><span
style="color: #339933;">;</span><br
/> <br
/> &nbsp; &nbsp; <span
style="color: #b1b100;">return</span> parent<span
style="color: #339933;">::</span><span
style="color: #004000;">save</span><span
style="color: #009900;">&#40;</span><span
style="color: #000088;">$conn</span><span
style="color: #009900;">&#41;</span><span
style="color: #339933;">;</span><br
/> &nbsp; <span
style="color: #009900;">&#125;</span><br
/> <span
style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div><p>And in the action :</p><div
class="codecolorer-container php twitlight" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table
cellspacing="0" cellpadding="0"><tbody><tr><td
style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br
/>2<br
/>3<br
/>4<br
/>5<br
/>6<br
/>7<br
/></div></td><td><div
class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span
style="color: #000000; font-weight: bold;">public</span> <span
style="color: #000000; font-weight: bold;">function</span> executeAction<span
style="color: #009900;">&#40;</span>sfWebRequest <span
style="color: #000088;">$request</span><span
style="color: #009900;">&#41;</span><br
/> <span
style="color: #009900;">&#123;</span><br
/> &nbsp; <span
style="color: #000088;">$obj</span> <span
style="color: #339933;">=</span> <span
style="color: #000000; font-weight: bold;">new</span> MyModelObject<span
style="color: #009900;">&#40;</span><span
style="color: #009900;">&#41;</span><span
style="color: #339933;">;</span><br
/> &nbsp; <span
style="color: #000088;">$obj</span><span
style="color: #339933;">-&gt;</span><span
style="color: #004000;">setUser</span><span
style="color: #009900;">&#40;</span><span
style="color: #000088;">$this</span><span
style="color: #339933;">-&gt;</span><span
style="color: #004000;">getUser</span><span
style="color: #009900;">&#40;</span><span
style="color: #009900;">&#41;</span><span
style="color: #009900;">&#41;</span><span
style="color: #339933;">;</span><br
/> <br
/> &nbsp; <span
style="color: #666666; font-style: italic;">// You can access the context with $this-&gt;getContext();</span><br
/> <span
style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div><p>++</p><p>Hugo.</p> ]]></content:encoded> </item> </channel> </rss>
<!-- This site's performance optimized by W3 Total Cache. Dramatically improve the speed and reliability of your blog!

Learn more about our WordPress Plugins: http://www.w3-edge.com/wordpress-plugins/

Minified using disk
Page Caching using disk (user agent is rejected)
Database Caching 3/18 queries in 0.060 seconds using disk

Served from: DSX4001-21.guardiandns.com @ 2010-03-12 18:42:27 -->