Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Suppose you have this in your config file:</p> <pre><code>... 'components' =&gt; array( 'parameters' =&gt; array( 'class' =&gt; 'path.to.parameters.php', 'applications' =&gt; array( 'productName' =&gt; array( 'tableName' =&gt; 'settings', 'property' =&gt; 'param1' ), ) ), ), ... </code></pre> <p>If you want to have <code>\Yii::app()-&gt;parameters-&gt;productName-&gt;tableName</code> return the value <code>"settings"</code>. Your application component would then have to override the <code>__get</code> magic method to check if <code>$this-&gt;applications</code> contains the <code>"productName"</code> key using <code>isset()</code> and return that key's value as an object instead of an array.</p> <p>The application component would look like this:</p> <pre><code>&lt;?php namespace Sakanade; class parameters extends \CApplicationComponent { public $cacheAll = false; public $dbConnectionId = null; public $applications = array(); public function __get($attr) { // If `$attr` is a key in `$this-&gt;applications`, return that if (is_array($this-&gt;applications) &amp;&amp; isset($this-&gt;applications[$attr])) { // Convert to an object return (object) $this-&gt;applications[$attr]; } // Return the default implementation by CApplicationComponent return parent::__get($attr); } } </code></pre> <p>I tested this by putting this in a controller:</p> <pre><code>$tableName = \Yii::app()-&gt;parameters-&gt;productName-&gt;tableName; print_r($tableName); // prints "settings" </code></pre> <p>Other properties that already exist in the component can be accessed normally:</p> <pre><code>var_dump(\Yii::app()-&gt;parameters-&gt;cacheAll); // false var_dump(\Yii::app()-&gt;parameters-&gt;dbConnectionId); // null </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload