Question

my Yii modules file structure looks like this

-yii
  -protected
     -modules
        -admin
           -controller
           -model
           -view
               -layout
                    -main.php
           -assets
               -css
                   -style.css
               -js
               -images
                   -logo.jpg

what i'm trying to do is access the logo.jpg from my protected/views/site/index.php. How do i do that?

Was it helpful?

Solution

Your should publish your assets first, then use this url. Add this code in your module:

class YourModule extends CWebModule
{
    private $_assetsUrl;

    public function getAssetsUrl()
    {
        if ($this->_assetsUrl === null)
            $this->_assetsUrl = Yii::app()->getAssetManager()->publish(__DIR__ . '/assets', false, -1, true);
        return $this->_assetsUrl;
    }

Then use this url:

$assets = $this->module->getAssetsUrl();
echo $assets . '/images/logo.jpg'
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top