小编Jon*_*nny的帖子

TableViewCell不会按预期重新加载

我有一个小应用程序跟踪玩家在体育游戏中的上场时间.我有一个体育游戏列表,你可以点击一个并开始跟踪游戏细节.我正在尝试这样做,以便如果游戏正在进行并且用户返回到游戏列表,则他们无法点击另一个游戏单元,因为它会覆盖活动游戏中的所有当前数据.

我几乎完成了这项工作.当游戏正在进行中并且我返回到体育游戏列表时,只有活动游戏可以访问并向用户显示它是活动的.但是当我回去重置那个游戏时,我希望体育游戏的tableView都可以访问.但他们不是.它仍然只显示一个活动游戏,所有其他游戏都无法访问.我在viewWillAppear中使用tableView.reloadData.我也在下面展示了相关代码.

// gameViewController -> shows all the games you can track
override func viewWillAppear(_ animated: Bool) {
    self.tableView.reloadData()
    for game in fetchedResultsController.fetchedObjects! {
        print("Game Opposition is \(game.opposition)")
        print("Is Playing? \(game.isPlaying)")
        print("Current Playing Time \(game.currentGameTime)")
        print("----------------------")
    }
}

// game cell view controller -> checks to see if any games are in progress
func isAnyGamesInProgress(games: [Game]) -> Bool {
     let inProgressGames = games.filter({ Int($0.currentGameTime) > 0 && $0.gameComplete == false })
if inProgressGames.isEmpty {
    return false
}
return true
 } …
Run Code Online (Sandbox Code Playgroud)

uitableview tableviewcell ios swift prepareforreuse

7
推荐指数
1
解决办法
174
查看次数

如何在Yii2中使用SASS/SCSS?

我想在一个新项目中使用sass/scss,但它不知何故不起作用.我正在使用yii2-asset-converter,当我尝试转换scss文件时,抛出以下错误:

Class @app/extensions/assetparser/vendors/phamlp/sass/SassParser does not exist

我正在检查路径../phamlp/并注意,文件夹sass resp.SassParser.php不存在.SassParser.php位于扩展供应商/ richthegeek/phpsass中,这是yii2-asset-converter所需要的.

我尝试了一些路径,如: @ vendor/richthegeek/phpsass

__DIR__/../../vendor/richthegeek/phpsass
Run Code Online (Sandbox Code Playgroud)

但它没有用.经过许多不成功的尝试,我希望你们中的一些人知道如何解决这个问题.

PS:我使用的是高级应用模板

sass yii2

6
推荐指数
1
解决办法
7732
查看次数

Yii2如何在菜单项的标签中添加类

如何在Label(item)上添加CSS类

例:

['label'=>'Home', 'url'=>['site/home']]

这不起作用

['label'=>'Home', 'class'=>'list-group-item', 'url'=>['site/index']],

yii2

6
推荐指数
1
解决办法
2万
查看次数

Yii Framework 2.0 GridView和来自连接表的数据

我有两个数据库表'user'和'role'.我使用Yii framework 2.0 Gii用User模型和UserSearch模型创建CRUD.默认情况下,Gii使用GridView :: widget作为"用户"模型的索引页面.

在UserSearch模型内部的搜索($ params)方法中,我使用以下代码将上述表连接在一起

$query = User::find()->with('role');
Run Code Online (Sandbox Code Playgroud)

查询一切正常.

默认情况下,Gii不包含来自views/user/index.php页面内GridView :: widget中的连接表'role'的数据.通过上面的连接查询,我可以从两个表中检索数据.在views/user/index.php页面中,我使用以下代码注入了GridView :: widget,以便它还包括连接表(角色)中的数据和列名.

<?= GridView::widget([
    'dataProvider' => $dataProvider,
    'filterModel' => $searchModel,
    'columns' => [
        ['class' => 'yii\grid\SerialColumn'],
        'userid',
        'username',
        'role.role_name',
        ['class' => 'yii\grid\ActionColumn'],
    ],
]); ?>
Run Code Online (Sandbox Code Playgroud)

使用GridView :: widget中包含的角色数据'role_name,一切正常.但问题是role_name没有搜索框.GridView :: widget仅为User属性创建搜索框.有没有办法为联接表'role'的属性添加搜索框,因为我还想搜索'role_name'以及User模型的其他属性.

php gridview yii2

6
推荐指数
1
解决办法
1万
查看次数

条件AppAssets

我有一个视图,我需要在我的标题中调用JQuery以及另一个JS库.对于所有其他页面,可以在文档末尾呈现它们.在Yii2中实现这一目标的最佳方法是什么?

目前我只是在我的AppAsset.php中这样做

public $js = [
  'https://code.highcharts.com/highcharts.js',
];
public $jsOptions = ['position' => \yii\web\View::POS_HEAD]; 
Run Code Online (Sandbox Code Playgroud)

我已经看过制作一个新的资产,但它似乎没有用,我不确定这是否是正确的方法.因为我不想在每个页面中首先渲染JS.

<?php

namespace app\assets;

use yii\web\AssetBundle;

class EarlyJavaScriptAsset extends AssetBundle
{
public $js = [
'https://code.highcharts.com/highcharts.js',
];
public $jsOptions = ['position' => \yii\web\View::POS_HEAD]; 

public $publishOptions = [
    'only' => [
        'report/report-1', // this is view folder location
    ]
];
}
Run Code Online (Sandbox Code Playgroud)

php yii2

6
推荐指数
1
解决办法
87
查看次数

.htaccess并过滤$ _GET

您好我正在编写一个配置文件页面脚本,在此脚本中我检查传入的$ _GET变量的值并验证它是一个整数,然后我根据$ _SESSION值验证此值以确认它们只能访问自己的帐户.代码如下所示:

// validate $_GET field 
if(isset($_GET['identity']) && filter_var($_GET['identity'], FILTER_VALIDATE_INT, array('min_range' => 1))) {


if(isset($_SESSION['user_identity']) && ((int)$_SESSION['user_identity'] === (int)$_GET['identity'])) { // if session exists and is === $_GET['identity']
// Proceed with code
Run Code Online (Sandbox Code Playgroud)

这样可以正常工作,例如,如果我尝试传递'0','2-2','abc'或没有值作为$ _GET值,查询正确失败并将它们重定向到主页.

然后我尝试做的是改变我的.htaccess文件,将URL映射到'profile/1',只是为了整理它.

RewriteRule ^profile$ profile.php
RewriteRule ^profile/([0-9]+)$ profile.php?identity=$1 [NC,L]
Run Code Online (Sandbox Code Playgroud)

我现在发现的是,页面不再使用上面那些无效的$ _GET参数重定向.它只是试图找到'profile/abc.

有谁知道为什么?

.htaccess mod-rewrite url-rewriting filter-var

5
推荐指数
1
解决办法
365
查看次数

Yii2 DatePicker

我正在为Yii2中的出生日期运行一个datePicker.我也试图展示这一年.我已经检查了JQuery文档http://jqueryui.com/datepicker/#dropdown-month-year,我想我能够实现这一目标changeYear.但它似乎没有用.这样做的方法是什么?这是我目前的代码.

<?= $form->field($model, 'date_of_birth')->widget(DatePicker::className(),[
   'name' => 'date_of_birth',
   'language' => 'en-GB',
   'dateFormat' => 'yyyy-MM-dd',
   'options' => [
      'changeMonth' => true,
      'changeYear' => true,
      'yearRange' => '1996:2099',
      'showOn' => 'button',
      'buttonImage' => 'images/calendar.gif',
      'buttonImageOnly' => true,
      'buttonText' => 'Select date'
    ],
]) ?>
Run Code Online (Sandbox Code Playgroud)

jquery-ui yii2

5
推荐指数
2
解决办法
5872
查看次数

如何为同一个表指定多个连接的别名?

我的模型中有两个关系定义在同一个表中

public function getCountry(){
    return $this->hasOne(Country::className(),['country_id' => 'country_id']);
}

public function getCurrency(){
    return $this->hasOne(Country::className(), ['country_id' => 'currency']);
}
Run Code Online (Sandbox Code Playgroud)

我想在我的查询中加入这两个关系.下面的代码显示错误.

Country::find()->joinWith(['country','currency'])->....
Run Code Online (Sandbox Code Playgroud)

也试过这个

Country::find()->joinWith(['country','currency as cur'])->....
Run Code Online (Sandbox Code Playgroud)

如何为第二关系指定别名?

yii2

5
推荐指数
2
解决办法
5909
查看次数

Yii2 REST API作为模块路由配置

我有一个现有的Yii2应用程序,并且一直在尝试将REST API作为附加模块来实现(也许模块不是解决此问题的正确方法?)但是我在配置路由结构时遇到了一些麻烦。根据以下指南,它不能完全正常工作,也不符合预期结果。

我建立了一个附加模块,如下所示:

module
  api
    controllers
      UserController.php
    Module.php
Run Code Online (Sandbox Code Playgroud)

UserController.php

<?php

namespace app\modules\api\controllers;

use yii\rest\ActiveController;

class UserController extends ActiveController
{
    public $modelClass = 'app\models\User';
}
Run Code Online (Sandbox Code Playgroud)

Module.php

<?php

namespace app\modules\api;

/**
 * onco module definition class
 */
class Module extends \yii\base\Module
{
    public $defaultController = 'user';
    /**
     * @inheritdoc
     */
    public $controllerNamespace = 'app\modules\api\controllers';

    /**
     * @inheritdoc
     */
    public function init()
    {
        parent::init();

        // custom initialization code goes here
    }
}
Run Code Online (Sandbox Code Playgroud)

在我的配置文件中,我添加了以下内容:

'request' => [
    ...
            'parsers' => [
                'application/json' …
Run Code Online (Sandbox Code Playgroud)

php api rest yii2

5
推荐指数
1
解决办法
5292
查看次数

为什么有些php类有一个空的init()方法?

例如,在Yii2框架中,yii\filters\AccessControl该类init()从其父类重写一个函数yii\base\Object.这个Object类又有一个像这样的构造方法:

    Class Object implements Configurable {
        public function __construct($config = [])
        {
            if (!empty($config)) {
                Yii::configure($this, $config);
        }
        $this->init(); // calls the method defined below
        }
    }
// and the definition of this init function ... 
    public function init()
    {
    }
Run Code Online (Sandbox Code Playgroud)

现在没有明显的使用编写这样一个空函数,除非你想用它来初始化他/她将来可能需要的一些属性.

但是那个__construct()方法的用法完全一样!我需要了解这种init()方法是如何有用的.

php yii2

4
推荐指数
1
解决办法
693
查看次数