我正在尝试为我的 View 添加物化 css,这是我的 View /layouts/index.php:
<?php
use yii\helpers\Html;
use yii\widgets\Menu;
?>
<?php $this->beginPage(); ?>
<html>
<head>
<!--Import materialize.css-->
<link
type="text/css"
rel="stylesheet"
href="<?php echo $this->theme->baseUrl; ?>/frontend/web/css/materialize.min.css"
media="screen,projection"/>
<link type="text/css"
rel="stylesheet"
href="<?php echo $this->theme->baseUrl ?>/frontend/web/css/style.css"
media="screen,projection"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="author" content="Imre Mehesz">
<meta name="description" content="A simple design based on Material UI and MaterializeCSS.">
<meta name="robots" content="all">
</head>
<body>
<?php $this->beginBody() ?>
<div class="container">
<!-- Navbar goes here -->
<nav>
<div class="nav-wrapper">
<a href="#" class="brand-logo right"><?php echo Html::encode(\Yii::$app->name); ?></a>
<?php
echo Menu::widget([
'options' => [
"id" => "nav-mobile",
"class" => "left side-nav"
],
'items' => [
['label' => 'Home', 'url' => ['site/index']],
['label' => 'About', 'url' => ['site/about']],
['label' => 'Contact', 'url' => ['site/contact']],
['label' => 'Login', 'url' => ['site/login'], 'visible' => Yii::$app->user->isGuest],
],
]);
?>
<a class="button-collapse" href="#" data-activates="nav-mobile"><i class="mdi-navigation-menu"></i></a>
</div>
</nav>
<!-- Page Layout here -->
<div class="row">
<div class="right col s12 m8 l9"> <!-- Note that "m8 l9" was added -->
<p>
<?php echo $content; ?>
</p>
</div>
<div class="left col s12 m4 l3"> <!-- Note that "m4 l3" was added -->
<div class="card">
<div class="card-image">
<img src="<?php echo $this->theme->baseUrl ?>/frontend/web/images/header.jpg">
<span class="card-title">TF Violet</span>
</div>
<div class="card-content">
<p>I am a very simple card. I am good at containing small bits of information.
I am convenient because I require little markup to use effectively.</p>
</div>
<div class="card-action">
<a href="#">This is a link</a>
</div>
</div>
</div>
</div>
<footer class="page-footer">
<div class="container">
<div class="row">
<div class="col l6 s12">
<h5 class="white-text">Footer Content</h5>
<p class="white-text text-lighten-1">You can use rows and columns here to organize your footer
content.</p>
</div>
<div class="col l4 offset-l2 s12">
<h5 class="white-text">Links</h5>
<li><a class="white-text" href="#!">Link 1</a></li>
<li><a class="white-text" href="#!">Link 2</a></li>
<li><a class="white-text" href="#!">Link 3</a></li>
<li><a class="white-text" href="#!">Link 4</a></li>
</div>
</div>
</div>
<div class="footer-copyright">
<div class="container white-text center">
© 2015 ThemeFactory.net
</div>
</div>
</footer>
</div>
<!--Import jQuery before materialize.js-->
<script type="text/javascript"
src="https://code.jquery.com/jquery-2.1.1.min.js">
</script>
<script type="text/javascript"
src="<?php echo $this->theme->baseUrl ?>/frontend/web/js/materialize.min.js">
</script>
<script type="text/javascript">
$(function () {
$(".button-collapse").sideNav();
});
</script>
<?php $this->endBody(); ?>
</body>
</html>
<?php $this->endPage(); ?>
此外,在配置中:
'components' => [
'assetManager' => [
'bundles' => [
'yii\web\JqueryAsset' => [
'js'=>[]
],
'yii\bootstrap\BootstrapPluginAsset' => [
'js'=>[]
],
'yii\bootstrap\BootstrapAsset' => [
'css' => [],
],
],
],
但它返回:
PHP Notice – yii\base\ErrorException
Trying to get property of non-object
并且这一行是高亮的:
href="theme->baseUrl; ?>/frontend/web/css/materialize.min.css"
我仍然不能使用这个主题:D
来自:http://www.bsourcecode.com/yiiframework2/install-new-theme-in-yiiframework-2/#sample-theme-layout
应用 Assets :
<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace frontend\assets;
use yii\web\AssetBundle;
/**
* @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0
*/
class AppAsset extends AssetBundle
{
public $basePath = '@webroot';
public $baseUrl = '@web';
public $css = [
'/frontend/web/css/materialize.css',
'/frontend/web/css/materialize.min.css',
];
public $js = [
'/frontend/web/js/materialize.js',
'/frontend/web/js/materialize.min.js',
];
public $depends = [
# 'yii\web\YiiAsset',
# 'yii\bootstrap\BootstrapAsset',
];
}
最佳答案
http://www.yiiframework.com/doc-2.0/yii-web-view.html#registerCssFile()-detail
是Yii注册CSS文件的方式,但是推荐通过assestBundles来完成。我现在使用它们并且非常喜欢它们。
http://www.yiiframework.com/doc-2.0/yii-web-assetbundle.html
在 $css 数组中只列出您要使用的文件。 http://www.yiiframework.com/doc-2.0/guide-structure-assets.html
<?php
namespace app\assets;
use yii\web\AssetBundle;
class AppAsset extends AssetBundle
{
public $basePath = '@webroot';
public $baseUrl = '@web';
public $css = [
'css/path_to_materialize.css',
];
public $js = [
];
public $depends = [
'yii\web\YiiAsset',
'yii\bootstrap\BootstrapAsset',
];
关于php - 添加 Materialize css 后尝试在 Yii2 上获取非对象错误的属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33277433/
总的来说,我对ruby还比较陌生,我正在为我正在创建的对象编写一些rspec测试用例。许多测试用例都非常基础,我只是想确保正确填充和返回值。我想知道是否有办法使用循环结构来执行此操作。不必为我要测试的每个方法都设置一个assertEquals。例如:describeitem,"TestingtheItem"doit"willhaveanullvaluetostart"doitem=Item.new#HereIcoulddotheitem.name.shouldbe_nil#thenIcoulddoitem.category.shouldbe_nilendend但我想要一些方法来使用
当我使用Bundler时,是否需要在我的Gemfile中将其列为依赖项?毕竟,我的代码中有些地方需要它。例如,当我进行Bundler设置时:require"bundler/setup" 最佳答案 没有。您可以尝试,但首先您必须用鞋带将自己抬离地面。 关于ruby-我需要将Bundler本身添加到Gemfile中吗?,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/4758609/
在控制台中反复尝试之后,我想到了这种方法,可以按发生日期对类似activerecord的(Mongoid)对象进行分组。我不确定这是完成此任务的最佳方法,但它确实有效。有没有人有更好的建议,或者这是一个很好的方法?#eventsisanarrayofactiverecord-likeobjectsthatincludeatimeattributeevents.map{|event|#converteventsarrayintoanarrayofhasheswiththedayofthemonthandtheevent{:number=>event.time.day,:event=>ev
我正在用Ruby编写一个简单的程序来检查域列表是否被占用。基本上它循环遍历列表,并使用以下函数进行检查。require'rubygems'require'whois'defcheck_domain(domain)c=Whois::Client.newc.query("google.com").available?end程序不断出错(即使我在google.com中进行硬编码),并打印以下消息。鉴于该程序非常简单,我已经没有什么想法了-有什么建议吗?/Library/Ruby/Gems/1.8/gems/whois-2.0.2/lib/whois/server/adapters/base.
大约一年前,我决定确保每个包含非唯一文本的Flash通知都将从模块中的方法中获取文本。我这样做的最初原因是为了避免一遍又一遍地输入相同的字符串。如果我想更改措辞,我可以在一个地方轻松完成,而且一遍又一遍地重复同一件事而出现拼写错误的可能性也会降低。我最终得到的是这样的:moduleMessagesdefformat_error_messages(errors)errors.map{|attribute,message|"Error:#{attribute.to_s.titleize}#{message}."}enddeferror_message_could_not_find(obje
我希望我的UserPrice模型的属性在它们为空或不验证数值时默认为0。这些属性是tax_rate、shipping_cost和price。classCreateUserPrices8,:scale=>2t.decimal:tax_rate,:precision=>8,:scale=>2t.decimal:shipping_cost,:precision=>8,:scale=>2endendend起初,我将所有3列的:default=>0放在表格中,但我不想要这样,因为它已经填充了字段,我想使用占位符。这是我的UserPrice模型:classUserPrice回答before_val
我有一个ModularSinatra应用程序,我正在尝试将Bootstrap添加到应用程序中。get'/bootstrap/application.css'doless:"bootstrap/bootstrap"end我在views/bootstrap中有所有less文件,包括bootstrap.less。我收到这个错误:Less::ParseErrorat/bootstrap/application.css'reset.less'wasn'tfound.Bootstrap.less的第一行是://CSSReset@import"reset.less";我尝试了所有不同的路径格式,但它
我有一个包含模块的模型。我想在模块中覆盖模型的访问器方法。例如:classBlah这显然行不通。有什么想法可以实现吗? 最佳答案 您的代码看起来是正确的。我们正在毫无困难地使用这个确切的模式。如果我没记错的话,Rails使用#method_missing作为属性setter,因此您的模块将优先,阻止ActiveRecord的setter。如果您正在使用ActiveSupport::Concern(参见thisblogpost),那么您的实例方法需要进入一个特殊的模块:classBlah
我有一个表单,其中有很多字段取自数组(而不是模型或对象)。我如何验证这些字段的存在?solve_problem_pathdo|f|%>... 最佳答案 创建一个简单的类来包装请求参数并使用ActiveModel::Validations。#definedsomewhere,atthesimplest:require'ostruct'classSolvetrue#youcouldevencheckthesolutionwithavalidatorvalidatedoerrors.add(:base,"WRONG!!!")unlesss
好的,所以我的目标是轻松地将一些数据保存到磁盘以备后用。您如何简单地写入然后读取一个对象?所以如果我有一个简单的类classCattr_accessor:a,:bdefinitialize(a,b)@a,@b=a,bendend所以如果我从中非常快地制作一个objobj=C.new("foo","bar")#justgaveitsomerandomvalues然后我可以把它变成一个kindaidstring=obj.to_s#whichreturns""我终于可以将此字符串打印到文件或其他内容中。我的问题是,我该如何再次将这个id变回一个对象?我知道我可以自己挑选信息并制作一个接受该信