Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Yes, Yii supports this. In fact, this is how I have some websites configured.</p> <p>(Of course, this is predicated on having all your sites on the same server. But I see that Evan has this. This would not work accross servers.)</p> <p><strong>Firstly</strong>, it would require that you move your code out of the web-root and into the document root. See <a href="http://www.yiiframework.com/wiki/116/moving-project-code-outside-of-webroot-plus-multiple-project-support/" rel="nofollow">here</a>.</p> <p><strong>Secondly</strong>, it requires that you use Yii AssetsBase. See <a href="http://www.yiiframework.com/wiki/148/understanding-assets/" rel="nofollow">here</a> and <a href="http://www.yiiframework.com/wiki/311/assetmanager-clearing-browser-s-cache-on-site-update/" rel="nofollow">there</a>. I found the asset management a bear to configure (but a breeze to work with). This is what I ended up with:</p> <p>In components/Controller.php include the following:</p> <pre><code> /** * @var registers which js, css, images have been published * See: http://www.yiiframework.com/wiki/311/assetmanager-clearing-browser-s-cache-on-site- update/ */ private $_assetsBase; public function getAssetsBase() { if ($this-&gt;_assetsBase === null) { Yii::app()-&gt;assetManager-&gt;newDirMode = 0755; Yii::app()-&gt;assetManager-&gt;newFileMode = 0644; $this-&gt;_assetsBase = Yii::app()-&gt;assetManager-&gt;publish( Yii::getPathOfAlias('application.assets'), false, -1, defined('YII_DEBUG') &amp;&amp; YII_DEBUG ); } return $this-&gt;_assetsBase; } </code></pre> <p>The above presupposes that your JS, CSS and images are located as follows:</p> <pre><code>protected/assets/js/mobiscroll-2.3.custom.min.js protected/assets/css/mobiscroll-2.3.custom.min.css protected/assets/img/einstein.png </code></pre> <p>Then in your views, call your assets as follows:</p> <pre><code>&lt;?php $cs-&gt;registerScriptFile($this-&gt;assetsBase.'/js/mobiscroll-2.3.1/js/mobiscroll-2.3.custom.min.js'); $cs-&gt;registerCssFile($this-&gt;assetsBase.'/js/mobiscroll-2.3.1/css/mobiscroll-2.3.custom.min.css'); ?&gt; &lt;img src="&lt;?php echo $this-&gt;assetsBase ?&gt;/img/einstein.png"&gt; </code></pre> <p>Finally, after you have made changes to your JS or CSS, you will want to force a cache refresh in all users' browsers. You do this by touching the (original) assets directory. This will force Yii to rehash the (published) assets directory. Subsequently, your JS &amp; CSS will be refreshed in all users' browsers. Do something like this:</p> <pre><code>$command = 'touch /path/to/your/website/protected/assets'; exec ( $command.' 2&gt;&amp;1', $output , $result ); if ($result === 0) { $message = 'Assets have been pointed; a new directory should now be hashed'; } else { $message = 'Looks like something went wrong. Assets not pointed?'; } // END if </code></pre>
 

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