Jerad Arul
Jerad Arul

Reputation: 73

CSS files are not working in server using yii2

I integrated the CSS and JS file in the asset file. On localhost it's working but when I uploaded my project files in cPanel, the UI is breaking. I can't understand where I'm making the mistake, please help me fix these issues.

Inside the backend folder, I uploaded my AdminLTE-2 CSS and JS files in the web folder. In the asset layout file, I gave the path.

backend/assets/loginAsset.php

namespace backend\assets;

use yii\web\AssetBundle;

/**
 * Main backend application asset bundle.
 */
class loginAsset extends AssetBundle
{
    public $basePath = '@webroot';
    public $baseUrl = '@web';
    public $css = [
        'bower_components/bootstrap/dist/css/bootstrap.min.css',
        'bower_components/font-awesome/css/font-awesome.min.css',
        'bower_components/Ionicons/css/ionicons.min.css',
        'css/AdminLTE.min.css',
        'plugins/iCheck/square/blue.css',
        '//fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,600,700,300italic,400italic,600italic',
        //'css/site.css',
    ];

    public $js = [
        '//oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js',
        '//oss.maxcdn.com/respond/1.4.2/respond.min.js',
        'bower_components/jquery/dist/jquery.min.js',
        'bower_components/bootstrap/dist/js/bootstrap.min.js',
        'plugins/iCheck/icheck.min.js',
    ];
    public $depends = [
        //'yii\web\YiiAsset',
        //'yii\bootstrap\BootstrapAsset',
    ];
}

Upvotes: 1

Views: 2115

Answers (2)

user9364055
user9364055

Reputation: 1

There is a fifth reason why you may not have any css. At the top of route\to\your\site\frontend\views\layouts\main.php or route\to\your\site\web\views\layouts\main.php there must be the following:

AppAsset::register($this);

Above this you should “use” the class, so either use frontend\assets\AppAsset; for advanced yii2 or use app\assets\AppAsset; for the yii2 basic. If you don’t register your CSS there is no CSS.

Upvotes: 0

Anees Hikmat Abu Hmiad
Anees Hikmat Abu Hmiad

Reputation: 3550

Depending on your code, the issue is usually one of these scenarios:

  1. File doesn't exist in Asset_Management/backend/web/css/AdminLTE.min.css
  2. File does not have a truth permission.
  3. Maybe you need to add a truth server configuration to handling Asset_Management since by default it must be backend/web/css/AdminLTE.min.css nested of Asset_Management/backend/web/css/AdminLTE.min.css
  4. File Name is wrong, spelling mistake.

Upvotes: 1

Related Questions