谁一开始就是大神?

PHP 第71页

PHP

按照文档【安装Yii】中的步骤摘取的代码,部署后有问题[2.0]

Bravesuper阅读(84)

YII部署问题

如上图,直接用composer下载下来的,部署后就报上面的问题,我观察了下,多了以下目录:
YII模板目录

首先这个问题,不能这么解决。
你需要把Composer和fxp/composer-asset-plugin都更新到最新版本。
其次看fxp/composer-asset-plugin的文档来配置对应的路径。
切记不要修改框架源码,如果是框架的BUG你应该提供一个pull request或者issues,以供官方修复。
这个需要到www.yiiframework.com去看看了,这边的貌似没有跟进。你需要按着最新的方法来创建文件。
图看不见,楼主
看你错误路径和目录本来就不一样啊,
你把文件目录按照 错误提示 重新拷贝下试试
用composer好像又慢又容易出错,直接用下载归档文件多好
说说我的解决方法吧,我的开发和部署环境都是linux,所以我用了proxychain,这个可以让你在命令行下用代理的神器。当然,首先你得有一个国外的 代理,然后走着代理安装,速度就杠杠的了。
多说一句,yii2用composer安装,仅仅使用国内的composer源镜像速度也很慢的,原因在于fxp/composer-asset-plugin这个插件。

怎么去掉验证码前面的字母?[2.0]

momodolphin阅读(75)

怎么去掉 验证码前面的字母?输入图片说明

$form->field($model, 'verifyCode', ['template' => "{input}\n{hint}\n{error}"])->widget(Captcha::className()..........
打开源码,删除verify code.
我只能说这么多了
设置’template’属性

怎么加载网站的ico图标[2.0]

Fionalemon阅读(82)

如题,在yii2中怎么加载一个ico图标

和别的网站一样的处理方式,没啥不一样
ico没有专门的加载吧,就放在根目录就行了吧
利用调试工具看一下资源文件有没有正常加载

如何批量插入User[2.0]

Cindyseagull阅读(84)

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

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

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

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

Jackbubble阅读(80)

我配置了三个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目录

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

richpony阅读(78)

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阅读(93)

在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

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

NeoKeo阅读(85)

如题,不在同一个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 的过程。

使用yii\bootstrap\ActiveForm时会自动引用yii自带的js,与模板的相冲突[2.0]

Jasonnice阅读(77)

输入图片说明
如题,在使用activeform之后,自动引入了js与模板的js相冲突,导致js验证无法生效,虽然没有太大影响,但毕竟是个bug,有什么解决方案吗?

二选一,保留其中一个js。
或者对其中一个进行修改,保证两个同时出现是不冲突。
给你模板的js改个名不就行了吗
我也一样,然后去掉了一个,完美运行
解决冲突的最好方法就是,覆盖!!

登录

找回密码

注册