谁一开始就是大神?

PHP 第71页

PHP

循环栏目下的所有二级栏目,每个栏目列出10条新闻。[1.1]

fationhope阅读(69)

现在分类只有一级和二级,知道一级的分类ID,可以查询出所有二级分类ID和名字,但是怎么循环查出每个分类下10条新闻,
现在控制器代码如下:

        $minlist = CateUtils::getMinCateList($cid); //获取所有下级栏目ID和名字
        foreach ($minlist as $k => $v) {
            $sql = "select id,catid,mincate,title from daquan_article where mincate = $k limit 5";
            $list['list1'] = Article::model()->findAllBySql($sql);
            var_dump($list);    //在这里可以每个二级栏目输出10条新闻,但是不知道怎么赋值到views

        }
        var_dump($list);  //这里只能输出第一个二级栏目的10条新闻

大神们帮忙看下,是哪里有问题。谢谢

$list['list1']
修改为
循环外怎么可能直接获得循环内的数据,美术老师教的?
比如有文章表 Article(Id,Category,InsertDate),现在要用SQL找出每种类型中时间最新的前N个数据组成的集合。
@N 就是你要取多少条

用户登录和自动登录的问题[2.0]

FionaJames阅读(69)

yii默认的用户登录,是以它原本提供的user表的结构进行验证的,但是,如果是原有的系统进行重构,原有的用户表设定并不是和yii提供的user表的结构类似,简单的说,密码的加密就不是按照yii提供的加密方式进行,也没有auth_key,access_token,那么,如果在这种结构上进行登录验证,如何做呢?

还有自动登录的问题,yii在设定了自动登录后,下次就不需要重新登录了,此时,如果管理员修改了用户的信息,比如,修改了用户的密码,那么,由于用户是自动登录的,也就意味着已经没有验证新密码,就访问到系统了,这种情况如何解决呢?

先解释自动登录的问题,就刚好用到auth_key,自动登录是根据cookie,获取cookie中用户id,然后去数据库获取用户信息,然后在查询出来的用户信息中auth_key和cookie中的auth_key进行匹配,在改密码后,会改auth_key字段的内容,匹配失败,要重新登录。
同理,access_token也是自动登录用的,一般是登录链接上带一长串字符,访问就可以登陆了。
没有这两个字段,access_token自动登录方式不能使用,cookie登录验证也会失败。
如果一定不用这2个字段,access_token自动登录方式不要用,cookie登录去掉auth_key验证(当然,这会出现你说的改密码不需要重登的问题。)。
呃呃呃呃呃呃,多点了一次,还不能删除了。

yii2中使用组件yii\widget\Menu输出的label内容带html时不会被解释,求帮助[2.0]

ACGlovely阅读(71)

直接上代码

$mainMenuItems = array();
	$mainMenuItems[] = [
		'label' => '<i class="glyphicon glyphicon-th-large"></i>首页',
		'type' => 'raw',
		'url' => ['site/index'],
		'options' => [
			'class' => ''
		],
	];

echo Menu::widget([
    'options' => [
	'class' => 'nav-tabs nav-stacked'
    ],
    'items' => $mainMenuItems
]);

如上的视图文件在页面中显示时这样的:
“&lt;i class="glyphicon glyphicon-th-large"&gt;&lt;/i&gt;首页”
而不是以html的形式显示,应该怎么办呢,知道的兄弟能否告知,不甚感激。

'type' => 'html',

执行composerrequiremdmsoft/yii2-admin"~2.0"发生错误[2.0]

loveLion阅读(73)

The "fxp/composer-asset-plugin" plugin requires composer-plugin-api 1.0.0, this *WILL* break in the future and it should be fixed ASAP (require ^1.0 for example).
PHP Fatal error:  Call to undefined method Fxp\Composer\AssetPlugin\Package\Version\VersionParser::parseLinks() in C:\Users\admin\AppData\Roaming\Composer\vendor\fxp\composer-asset-plugin\Repository\VcsPackageFilter.php on line 272

Fatal error: Call to undefined method Fxp\Composer\AssetPlugin\Package\Version\VersionParser::parseLinks() in C:\Users\admin\AppData\Roaming\Composer\vendor\fxp\composer-asset-plugin\Repository\VcsPackageFilter.php on line 272

composer global require "fxp/composer-asset-plugin:~1.1.1"
先执行这个。yiichina的文档太old了,需要升级

(新手求助)AR接收不到表单数据[2.0]

richpony阅读(70)

use yii\helpers\Html;
use yii\bootstrap\ActiveForm;
use frontend\models\Post;
$this->title = '发帖';
    $this->params['breadcrumbs'][] = $this->title;
<?php $form=ActiveForm::begin([
                'id' => 'post-form',
                'options' => ['class' => 'class_name'],
                'action'=>'index.php?r=index/post',
                'method'=>'post',
            ]); 
?>
<?= $form->field($model,'title')->textInput()->label('标题');?>

            <?= $form->field($model,'content')->textarea(['rows'=>6,'id'=>'editor','class'=>'col-sm-1 col-md-12'])->label('文章');?>

            <div class="form-group">
            <?=  Html::submitButton('提交', [
                'class'=>'btn btn-primary',
                'name' =>'submit-button'])?>
            </div>

            <?php ActiveForm::end();?>

view

namespace frontend\controllers;

use yii;
use frontend\models\Post;
use yii\web\Controller;

class IndexController extends Controller{
    public function actionIndex(){

//        $model =new Post();
        return $this->render('post',[
                'model' => new Post()
            ]);
    }
    public function actionPost(){

        $model =new Post();

        if(yii::$app->request->post())
        {
            $model->title=yii::$app->request->post('title');
            $model->content=yii::$app->request->post('content');
            $model->save();
            return $this->render('post_success',[
                'model'=>$model
            ]);
        }
        else
        {
            return $this->render('post',[
                'model'=>$model
            ]);
        }
    }
}

controller

namespace frontend\models;

use Yii;


class Post extends \yii\db\ActiveRecord
{

    public $title;
    public $content;

    public static function tableName()
    {
        return 'post';
    }

    public function rules()
    {
        return [
            [['title'], 'required','message' => '标题不能为空.'],
            [['content'],'required','message' => '文章内容不能为空.'],
            [['title'], 'string', 'max' => 50],
            [['content'], 'string', 'max' => 200],
        ];
    }

    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'title' => 'Title',
            'content' => 'Content',
        ];
    }
}

model

刚接触YII的一个新手

你要看一下 HTML 上的 ActiveForm
你取用的方式是 name = “xxxx”
我記得ActiveForm 是已陣列方式呈現 name =”ModelName[……]”
如果不確定的話:
你大可直接 $_POST 看看傳入值是長甚麼樣子
楼主应该打开firebug,查看一下网络传输参数,一看便知。

yii2中migrate注释、索引[2.0]

HazelJames阅读(84)

在yii2中写迁移脚本,怎么添加普通索引,怎么写注释。

迁移脚本中不为空可以用not_null()这个方法,默认值有defaultValue()

那么普通索引以及注释呢?

非常感谢大家的回复,下面是我实现的方式,献丑了、、、

$this->createTable(self::TBL_NAME, [
            'id' => Schema::TYPE_PK,
            'user_id' => Schema::TYPE_INTEGER . ' NOT NULL COMMENT "用户ID"',
            'path' => Schema::TYPE_STRING . ' NOT NULL COMMENT "路径"',
            'created_at' => Schema::TYPE_INTEGER . ' NOT NULL COMMENT "上传时间"'
        ], $tableOptions);

普通索引用$this->index()
参考yii自带的migrate文件
你所需要的comment函数,将在不久的将来支持。
Comment methods for schema builder

如何批量插入User[2.0]

Cindyseagull阅读(74)

需要批量插入学生啊,但是password字段如何搞定?

我想直接在mysql里面插入,密码是怎么加密的?有方法吗?

如果密码可以一样,你就在yii2存一条,然后拷贝出来,
如果不一样,每次都要加密,就直接在程序里操作了,不要直接在mysql了。
如果是安装了yii2-user模块,直接mysql肯定不行,通过程序也很简单:

apache配置virtualHost后。localhost无法访问www目录[2.0]

Jackbubble阅读(72)

我配置了三个virtualHost.
使用这三个vituralHost可以访问相应的应用 。现在下面三个的配置已经生效。

但是我现在想用localhost访问 www目录时,却直接被转到basic/web。换句话说就是直接显示basic应用的内容了。

<VirtualHost *:80>
    ServerAdmin webmaster@dummy-host.example.com
    DocumentRoot "D:/wamp/www/basic/web"
    <Directory "D:/wamp/www/basic/web">
        RewriteEngine on
        Allow from all
        # If a directory or a file exists, use the request directly
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_FILENAME} !-d
        # Otherwise forward the request to index.php
        RewriteRule . index.php
    </Directory>
    ServerName www.yii2.com
    ServerAlias www.yii2.com
    ErrorLog "logs/yii2.com-error.log"
    CustomLog "logs/yii2.com-access.log" common
</VirtualHost>

<VirtualHost *:80>
    ServerAdmin webmaster@dummy-host.example.com
    DocumentRoot "D:/wamp/www/yiiadv/frontend/web"
    <Directory "D:/wamp/www/yiiadv/frontend/web">
        RewriteEngine on
        Allow from all
        # If a directory or a file exists, use the request directly
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_FILENAME} !-d
        # Otherwise forward the request to index.php
        RewriteRule . index.php
    </Directory>
    ServerName www.yiiadv.com
    ServerAlias www.yiiadv.com
    ErrorLog "logs/yiiadv.com-error.log"
    CustomLog "logs/yiiadv.com-access.log" common
</VirtualHost>
<VirtualHost *:80>
    ServerAdmin webmaster@dummy-host.example.com
    DocumentRoot "D:/wamp/www/yiiadv/backend/web"
    <Directory "D:/wamp/www/yiiadv/backend/web">
        RewriteEngine on
        Allow from all
        # If a directory or a file exists, use the request directly
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_FILENAME} !-d
        # Otherwise forward the request to index.php
        RewriteRule . index.php
    </Directory>
    ServerName www.backend.yiiadv.com
    ErrorLog "logs/yiiadv.com-error.log"
    CustomLog "logs/yiiadv.com-access.log" common
</VirtualHost>

Apache中没有捕获到的主机名,默认使用第一个虚拟主机。
问题描述不明不白..
确认你的配置已生效,
确定各端口都正常访问,
再确认没有别的规则指向www目录

请教个事,yiirestful接口提供的四个方法get,delete,put[2.0]

AniLion阅读(78)

在postman插件中使用是正常的,但是使用post创建新的用户的时候传参数一直为空,查看了数据库插入了一条数据,不过数据的用户名和密码为空,更新时间什么的就不为空,再次执行就报错了,请问什么原因
代码是这样的:

<?php
/**
 * Created by PhpStorm.
 * Date: 11/13/15
 * Time: 5:25 PM
 */

namespace api\controllers;


use yii\rest\ActiveController;

class UserController extends ActiveController
{
    public $modelClass = 'common\models\User';

}

Body
x-www-form-urlencoded

yii子模块如何调用父模块的动作[2.0]

NeoKeo阅读(75)

如题,不在同一个module里,怎么调用其他module的动作action。或者在frontend里有一个module,在这个子module怎么调用frontend的动作呢?谢谢。

比如,在子模块里,想$this->redirect(['site/index'])总是失败的,一般跳到子模块下的site/index,加上frontend/site/index却无法访问。

frontend/site/index 前面加上 / 即可:
Guide Handling Requests – Routing and URL Creation – Creating URLs 里面讲到:
你可以读读这节内容,了解一下 Yii 将 route 转换成 url 的过程。

登录

找回密码

注册