谁一开始就是大神?

PHP 第80页

PHP

有知道怎么用dektrium/yii2-user这个扩展的吗?注册后验证邮件发送失败[2.0]

AibyLion阅读(93)

配置好mailer,自己写controller能够发出邮件,我用的163和qq邮件都成功。但是用yii2-user注册后显示_Swift_TransportException Expected response code 250 but got code "501", with message "501 mail from address must be same as authorization user_。不知道怎么回事.我已经配置了模块

'modules' => [
    'user' => [
        'class' => 'dektrium\user\Module',
        'enableUnconfirmedLogin' => true,
        'confirmWithin' => 21600,
        'cost' => 12,
        'admins' => ['admin'],
             ],     
        ],
    ]
]

这是反垃圾邮件系统约束条件,501 mail from address must be same as authorization user 已经讲得很清楚了。
修改一下Mailer.phpsendMessage()函数中的setFrom($this->sender)语句的参数,改成和你配置mailer时用的邮件地址一样即可。
在config目录下的params.php
adminEmail的设置也要修改。
我的设置,首先我用的是basic版
在config/web.php中
/*’user’ => [
*/将原来的user注释掉,
在components中添加:
‘mailer’ => [
然后在components外添加:
‘modules’ => [
在config/param.php中
//’adminEmail’ => ‘admin@example.com’, 改为

怎么module模块下的默认控制器?[2.0]

Cleverlove阅读(103)

如题,我module模块下有admin控制器,我该怎么指定底下的IndexController为默认控制器呢?默认的事Default控制器

在 component 可以指定(但我只是過 defaultRoute)
網路上說 也可以用 defaultController 你試試看
Module.php 里面,可以自己重写 defaultRoutedefaultController 属性。

AssetBundleUpdateNotWorking[2.0]

JasonLion阅读(89)

剛使用 AssetBundle 調整 js 前後順序

位置是 protect/modules/order/assets

namespace app\modules\order\assets;

use yii\web\AssetBundle;

class Asset extends AssetBundle
{
    public $sourcePath = '@app/modules/order/js';
    public $publishOptions = [
        'forceCopy' => true
    ];
    public $css = [

    ];
    public $js = [
        'crud.js',
    ];
    public $depends = [
        'yii\web\YiiAsset',
        'yii\bootstrap\BootstrapAsset',
        'app\assets\AppAsset',
    ];
}

當我修改 js 時候, 重整畫面時
web/asset/xxxxx 都不會更新
所以嘗試 =>

public $publishOptions = [
    'forceCopy' => true
]; //效果一樣沒有成功

看網路解說也在設定的地方加上了 linkAssets
但看官網說明的方式又不太符合我的要求… (也可以說有點看不懂)

'components' => [
       'assetManager' => [
            'linkAssets' => true,
        ],
]

有甚麼辦法能在 時更新在 asset 載入的 js 呢!!

这应该是有缓存吧.
你清除下你本地缓存看看

2.0集成第三方类库[2.0]

lionfrog阅读(98)

我在yii2中要使用阿里百川的类库,它带有一个autoloader的php,我在入口脚本index.php里面引入了,那么我怎么在controller里面引用她的类啊

直接使用,因为你引用了autoloader,它会自动引入的
要看第三方有没有使用命名空间了,如果有就需要引用他的命名空间,如果没有那就要使用 “\”
我也是上周刚了解的,没有用命名空间的类库,include之后,就相当于在根命名空间中一样了

请问ActiveForm的textInput可以设置缺省值么?[2.0]

lionslim阅读(88)

如题,类似dropDownList里面的prompt的那种实现,例如表单中针对该文本框没有值的时候展示缺省值,有值的时候展示实际值。

可以在model里指定默认值,详情参考手册的核心验证器
http://www.yiichina.com/doc/guide/2.0/tutorial-core-validators
// 若 "country" 为空,则将其设为 "USA"
['country', 'default', 'value' => 'USA']
这种情况应该用 placeholder 吧,如果不符合你的要求,只写用 js 去实现了。
可以在controller逻辑中,在render数据的时候初始化默认值
在action中render的时候赋值

期望在上传文件的时候自动按时间创建文件夹,以保存上传文件[2.0]

lionpony阅读(90)

model代码如下:

public function upload(){
    if($this->validate()){
        if(!file_exists('upuploads/'.date('Y/m/d',time()))){
            mkdir('upuploads/'.date('Y/m/d',time()));
        }
        $this->imageFile->saveAs('uploads/'.date('Y/m/d',time()).'/'.rand(000,999).'.'.$this->imageFile->extension);
        return true;
    }else{
        return false;
    }
}
  1. 报错:mkdir(): No such file or directory
  2. 尝试解决:修改uploads的权限为777,但未来创建的文件夹都没有777权限

linux服务器 mkdir() 后加 chmod()

如何扩展YII提供的uploadfile类?[2.0]

lionKeo阅读(93)

请教一下,如果要扩展一个yii的类库,比如继承uploadfile类做一个缩略图类,有没有啥标准的写法?
自己写的类放到哪个文件夹合适?如何做到自动加载?

看看文档 在config里配置aliases,这样你可以做你想干的了

GridView格式化日期两种格式化的疑问?[2.0]

likelydolphin阅读(91)

输入图片说明

'format' => ['date', 'Y-m-d H::i::s'], 格式化时间前面2条记录错误了,而且只错了月份,而后2条记录的时间确实正确的

确认过数据库,红色框部分是正确的

求解疑惑???

'format'=>['date', 'php:Y-m-d H:i:s']
设置一下timeZone.

ubuntu上的mysql启动不了了

ecyCherry阅读(95)

sbw@~$mysql -uroot -p
Enter password: 
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)

错误日志显示

150907 14:23:02 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
150907 14:23:02 [Warning] Using unique option prefix key_buffer instead of key_buffer_size is deprecated and will be removed in a future release. Please use the full name instead.
150907 14:23:02 [Note] /usr/sbin/mysqld (mysqld 5.5.44-0ubuntu0.14.04.1) starting as process 11631 ...
150907 14:23:02 [Warning] Using unique option prefix myisam-recover instead of myisam-recover-options is deprecated and will be removed in a future release. Please use the full name instead.
150907 14:23:02 [Note] Plugin 'FEDERATED' is disabled.
150907 14:23:02 [ERROR] Function 'innodb' already exists
150907 14:23:02 [Warning] Couldn't load plugin named 'innodb' with soname 'ha_innodb.so'.
150907 14:23:02 [ERROR] Function 'federated' already exists
150907 14:23:02 [Warning] Couldn't load plugin named 'federated' with soname 'ha_federated.so'.
150907 14:23:02 [ERROR] Function 'blackhole' already exists
150907 14:23:02 [Warning] Couldn't load plugin named 'blackhole' with soname 'ha_blackhole.so'.
150907 14:23:02 [ERROR] Function 'archive' already exists
150907 14:23:02 [Warning] Couldn't load plugin named 'archive' with soname 'ha_archive.so'.
150907 14:23:02 InnoDB: The InnoDB memory heap is disabled
150907 14:23:02 InnoDB: Mutexes and rw_locks use GCC atomic builtins
150907 14:23:02 InnoDB: Compressed tables use zlib 1.2.8
150907 14:23:02 InnoDB: Using Linux native AIO
150907 14:23:02 InnoDB: Initializing buffer pool, size = 128.0M
150907 14:23:02 InnoDB: Completed initialization of buffer pool
InnoDB: Error: log file ./ib_logfile0 is of different size 0 50331648 bytes
InnoDB: than specified in the .cnf file 0 5242880 bytes!
150907 14:23:02 [ERROR] Plugin 'InnoDB' init function returned error.
150907 14:23:02 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
150907 14:23:02 [ERROR] Unknown/unsupported storage engine: InnoDB
150907 14:23:02 [ERROR] Aborting

150907 14:23:02 [Note] /usr/sbin/mysqld: Shutdown complete

150907 14:23:02 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended

重装,紫薯布丁~

redirect无法打开网页[2.0]

fationsea阅读(93)

if ($model->load(Yii::$app->request->post()) && $model->login()) {
    return $this->redirect(['panel/home/index']);
}

代码如上很简单,就是登录验证通过就redirect到http://host/panel/home/index,但是在本地和测试服务器上正常跳转了,在正式服务器上却会产生了网页刷新的动作却没有跳转到http://host/panel/home/index,我在return $this->redirect(['panel/home/index']);前加上echo"success";die();后成功输出了success,说明的确是运行到了redirect这里的,但是为什么会正式服务器上无法跳转?

两个环境服务器配置不一样。
试试
header(“Location:$url”);exit;
试试
return $this->redirect(‘panel/home/index’);
试试 return $this->redirect(['/panel/home/index']);
多了一个斜杠。
打开浏览器,切换到调试中的“network”看看 response中的header中是否有重定向302的状态码

登录

找回密码

注册