小编Jon*_*nny的帖子

onbeforeunload 并不总是有效

我正在制作一个简单的脚本,用于在用户访问页面和离开页面时保存一些数据以及其他一些页面详细信息。该脚本“有效”,但并非始终有效。它似乎偶尔工作。我没有收到控制台错误。服务器端工作正常。

window.onload = function() {


var timeStarted, i, c, l, timeLeft, pageData; 

timeStarted = new Date().getTime();

i = <?php echo $model->id; ?>;
c = <?php echo $model->cat; ?>;
l= <?php echo $model->loc; ?>;

window.onbeforeunload = function(){

timeLeft = new Date().getTime();

pageData = [{name: 'timeStarted', value: timeStarted}, 
            {name: 'i', value: job},
            {name: 'c', value: cat},
            {name: 'l', value: loc},
            {name: 'timeLeft', value: timeLeft}];

// Set url for JavaSCript
var url = '<?php echo Yii::app()->createUrl("item/viewedItemInformation"); ?>';

<?php echo CHtml::ajax(array(
        'url'=>'js:url',
        'data'=> "js: …
Run Code Online (Sandbox Code Playgroud)

javascript onbeforeunload

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

NSSet没有下标成员

我有一个CoreData对象,其关系是NSSet.我正在尝试使用它作为我的dataSource,但得到以下内容

    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {

    let cell = playerTableView.dequeueReusableCellWithIdentifier("Cell")! as UITableViewCell
    cell.textLabel?.text = self.game.players[indexPath.row]
    return cell
}
Run Code Online (Sandbox Code Playgroud)

我如何在tableView中使用我的NSSet,我相信这将是无序的,所以每次都有可能不同,所以我怎么能订购这个集合?

uitableview nsset swift

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

在跨表计数时如何减少对DB的调用次数

我有一个类别表,列出了大约35种可能的类别.然后我还有一个Item表,其中一个外键与category表中的一个类别相关.在我的索引页面上,我希望只显示每个类别中有多少项目.我只是不确定在构建更高效的查询和减少对数据库的调用数量方面,最好的方法是什么.

任何想法都会很棒

谢谢

sql performance

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

Yii Query Builder多个where子句

我在我的堆栈中注意到我的查询没有正确执行,因为我在querybuilder中有多个where子句.所以我在Yii Query构建器中查看了这个帖子Multiple call where

应用我读过的内容,但查询仍然没有结合where语句.我究竟做错了什么?

            $command = Yii::app()->db->createCommand()
        ....
        ->where(array('in', 'u.id', $licenses), array('and', 'i.date_added > DATE_SUB(u.date_expired, INTERVAL  30 DAY)'));
        //->where(array('and', 'i.date_added > DATE_SUB(u.date_expired, INTERVAL  30 DAY)'));
        //->where(array('and', 'u.date_expired > CURDATE()'))
        ->group('u.id');
Run Code Online (Sandbox Code Playgroud)

这些是3个单独的陈述,但我在阅读时将它们合并,但结果仍然相同.只有1个where子句.

yii query-builder

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

$_POST 中的多个键值

我目前正在使用 Yii 2 构建一个小测验,我想检查我的方法。我的测验是每页一个问题,我使用一个会话来获取所有问题 ID 和答案。我应该补充一点,我有多个测验,因此测验 ID 不一定是增量的。

当答案发回时,我需要捕获问题 ID 和所选的选项 ID。这些格式为

<input type="radio" name="6" value="12"> // 6 being the question and 12 the option_id
Run Code Online (Sandbox Code Playgroud)

因为我不知道下一个问题是什么,因为我只是++通过数组递增。

如果我将代码更改为这样

<input type="radio" name="question" value="6,12">
Run Code Online (Sandbox Code Playgroud)

这是获取信息的好方法吗,因为我总是知道这个问题称为问题,我可以分解该值或以某种方式拆分它,或者我应该使用方括号?

我不确定如何在 Yii 2 中执行此操作。我当前的代码是:

echo Html::radioList('question', NULL, [$q->question_id . ',' . $q->question_option_id => $q->option], ['class' =>'radioId']);
Run Code Online (Sandbox Code Playgroud)

html php post

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

如何在yii2中使用rest api登录用户

我是 yii2 的新用户,我希望使用 REST API 登录用户,但无法做到这一点。我已经从这个博客设置了基本的 REST API:

budiirawan.com/setup-restful-api-yii2/

之后我创建了:

api\modules\v1\controllers\SiteController.php

<?php
namespace api\modules\v1\controllers;

use Yii;
use yii\filters\AccessControl;
use yii\web\Controller;
use common\models\LoginForm;
use yii\filters\VerbFilter;
use yii\rest\ActiveController;
/**
 * Site controller
 */
class SiteController extends ActiveController
{
    /**
     * @inheritdoc
     */
    public $modelClass = 'api\modules\v1\models\user';    


    public function actionIndex()
    {
            if (!\Yii::$app->user->isGuest) {
            return $this->goHome();
        }

        $model = new LoginForm();
        if ($model->load(Yii::$app->request->post()) && $model->login()) {
            return $this->goBack();
        } else {
            return $this->render('login', [
                'model' => $model,
            ]);
        }
    }

    public function actionLogout() …
Run Code Online (Sandbox Code Playgroud)

api rest yii2

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

使用mpdf将内容添加到第二页

我正在使用https://github.com/kartik-v/yii2-mpdf在Yii2中创建PDF.我有我的第一页,但我需要添加一个分页符,并确保我在新页面上启动第二条信息.我不确定该怎么做.我试过了:

    public function actionReports()
{
  $data = date('d F Y',time());
  $content = $this->renderPartial('_billing', [
    'model' => $data,
  ]);

  $doc = new Pdf([
    // set to use core fonts only
    'mode' => Pdf::MODE_UTF8,
    // A4 paper format
    'format' => Pdf::FORMAT_A4,
    // portrait orientation
    'orientation' => Pdf::ORIENT_PORTRAIT,
    // stream to browser inline
    'destination' => Pdf::DEST_BROWSER,
    // your html content input
    'content' => $content,
  ]);

  return $doc->render();
}
Run Code Online (Sandbox Code Playgroud)

视图

use yii\helpers\Html;

?>
<div class="container">
<div class="row">
<div class="col-lg-6 col-lg-offset-3 text-center">
  <?= …
Run Code Online (Sandbox Code Playgroud)

php mpdf yii2

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

如何用PHP打开一个新选项卡

我正在尝试用Php打开一个新选项卡,然后显示一个图像.我找到了openWindow()函数,但它适用于Javascript.我只想使用Php.

我的Php代码:

<?php
function showImage() {
  $my_img = imagecreate( 200, 80 );
  $background = imagecolorallocate( $my_img, 0, 0, 255 );
  $text_colour = imagecolorallocate( $my_img, 255, 255, 0 );
  $line_colour = imagecolorallocate( $my_img, 128, 255, 0 );
  imagestring( $my_img, 4, 30, 25, "Quote", $text_colour );
  imagesetthickness ( $my_img, 5 );
  imageline( $my_img, 30, 45, 165, 45, $line_colour );

  header( "Content-type: image/png" );
  imagepng( $my_img, "quote.png" );
  imagecolordeallocate( $line_color );
  imagecolordeallocate( $text_color );
  imagecolordeallocate( $background );
}
?>
Run Code Online (Sandbox Code Playgroud)

任何帮助,将不胜感激!

html javascript php image new-window

-2
推荐指数
1
解决办法
6749
查看次数

Codigniter查询错误

使用时:

$cols_string = implode(',',$cols_array;
$query = "INSERT INTO TB_BATs (col1, col2, col3  VALUES $cols_string "      
$this->db->query($query);
Run Code Online (Sandbox Code Playgroud)

我明白了 "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 3 "

接下来是SQL查询,但是当我在PHPMYADMIN中复制查询时它工作正常,如果将其复制到$query字符串中它也可以正常工作,问题出现时才会使用$cols_string

php mysql sql codeigniter

-3
推荐指数
1
解决办法
69
查看次数