I want to add an image to [font=“Courier New”]brandLabel[/font] but I’m unsure as to how I should add images to my Yii app.
Currently I’m creating an advanced app but I don’t know where I should put my images or how I reference an image from [font=“Courier New”]main.php[/font] where the [font=“Courier New”]NavBar[/font] is specified.
Usually, I make resources folder in webroot folder where I keep all JS, CSS and ICONS. If you want to display image from this folder you can do it this way:
There are no any rules based to keep your image folders.
However, it is easy to fetch directory that is in your root of web-server ex: inside "public_HTML". But it is not a compulsion, it depends in how you fetch and what parameter and logic you use to fetch images.
Suppose you have a theme folder that is rendering layout and view style to your files then you can keep you image folder there also and call it to display using
but for this you need to add a small chunk of code in your config/main.php file that tells your application where should it get themes from
// This is the main Web application configuration. Any writable
// CWebApplication properties can be configured here.
return array(
'basePath' => dirname(__FILE__) . DIRECTORY_SEPARATOR . '..',
'name' => 'Your Site',
'theme' => 'frontend',
So it depends in your logic and your programming standerd.
You can also use the syntax DURI gave you but you can also do it in complex ways.
'upload_dir' => '/var/home/www/main_site_root_directory/upload/', // for woring with paths
'upload_url' => '/upload/', // for working with urls
Then use it in your project something like this:
class SomeModel extends CActiveRecord {
public static $dir = 'brandlabel';
public static function getBrandLabelUploadDir(){
return Yii::app()->params['upload_dir'].self::$dir.DIRECTORY_SEPARATOR;
}
public static function getBrandLabelUploadUrl(){
return Yii::app()->params['upload_url'].self::$dir.'/';
}
}