Zend_View-Helpers-UserAgent.xml 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!-- Reviewed: no -->
  3. <sect3 id="zend.view.helpers.initial.user-agent">
  4. <title>UserAgent View Helper</title>
  5. <sect4 id="zend.view.helpers.initial.user-agent.intro">
  6. <title>Overview</title>
  7. <para>
  8. This view helper provides the ability to inject and later retrieve a
  9. <classname>Zend_Http_UserAgent</classname> instance for use in branching display logic
  10. based on device capabilities.
  11. </para>
  12. </sect4>
  13. <sect4 id="zend.view.helpers.initial.user-agent.quick-start">
  14. <title>Quick Start</title>
  15. <para>
  16. In most cases, you can simply retrieve the User-Agent and related device by calling the
  17. helper. If the <classname>UserAgent</classname> was configured in the <link
  18. linkend="zend.application.available-resources.useragent">
  19. bootstrap</link>, that instance will be injected already in the helper; otherwise, it
  20. will instantiate one for you.
  21. </para>
  22. <programlisting language="php"><![CDATA[
  23. <?php if ($this->userAgent()->getDevice()->hasFlash()): ?>
  24. <object ...></object>
  25. <?php endif ?>
  26. ]]></programlisting>
  27. <para>
  28. If you initialize the <classname>UserAgent</classname> object manually, you can still
  29. inject it into the helper, in one of two ways.
  30. </para>
  31. <programlisting language="php"><![CDATA[
  32. // Pull the helper from the view, and inject:
  33. $helper = $view->getHelper('userAgent');
  34. $helper->setUserAgent($userAgent);
  35. // Pass the UserAgent to the helper:
  36. $view->userAgent($userAgent);
  37. ]]></programlisting>
  38. </sect4>
  39. <sect4 id="zend.view.helpers.initial.user-agent.methods">
  40. <title>Available Methods</title>
  41. <variablelist>
  42. <varlistentry id="zend.view.helpers.initial.user-agent.methods.user-agent">
  43. <term>
  44. <methodsynopsis>
  45. <methodname>userAgent</methodname>
  46. <methodparam>
  47. <funcparams>Zend_Http_UserAgent $userAgent = null</funcparams>
  48. </methodparam>
  49. </methodsynopsis>
  50. </term>
  51. <listitem>
  52. <para>
  53. Use this method to set or retrieve the <classname>UserAgent</classname>
  54. instance. Passing an instance will set it; passing no arguments will retrieve
  55. it. If no previous instance has been registered, one will be lazy-loaded using
  56. defaults.
  57. </para>
  58. </listitem>
  59. </varlistentry>
  60. <varlistentry id="zend.view.helpers.initial.user-agent.methods.set-user-agent">
  61. <term>
  62. <methodsynopsis>
  63. <methodname>setUserAgent</methodname>
  64. <methodparam>
  65. <funcparams>Zend_Http_UserAgent $userAgent</funcparams>
  66. </methodparam>
  67. </methodsynopsis>
  68. </term>
  69. <listitem>
  70. <para>
  71. If you have an instance of the helper -- for instance, by calling the view
  72. object's <methodname>getHelper()</methodname> method -- you may use this method
  73. to set the <classname>UserAgent</classname> instance.
  74. </para>
  75. </listitem>
  76. </varlistentry>
  77. <varlistentry id="zend.view.helpers.initial.user-agent.methods.get-user-agent">
  78. <term>
  79. <methodsynopsis>
  80. <methodname>getUserAgent</methodname>
  81. </methodsynopsis>
  82. </term>
  83. <listitem>
  84. <para>
  85. Retrieves the <classname>UserAgent</classname> instance; if none is registered,
  86. it will lazy-load one using default values.
  87. </para>
  88. </listitem>
  89. </varlistentry>
  90. </variablelist>
  91. </sect4>
  92. </sect3>