谁一开始就是大神?

PHP 第83页

PHP

哪位帅哥把这2个c#方法,给转成php5.5的方法。谢谢!!![2.0]

CGqueen阅读(70)

php水平实在不行。只有请教各位了。 希望有朋友帮忙下。 不胜感激。

public static string Decrypt(string Text, string sKey)
        {
            DESCryptoServiceProvider provider = new DESCryptoServiceProvider();
            int num = Text.Length / 2;
            byte[] buffer = new byte[num];
            for (int i = 0; i < num; i++)
            {
                int num3 = Convert.ToInt32(Text.Substring(i * 2, 2), 0x10);
                buffer[i] = (byte) num3;
            }
            provider.Key = Encoding.ASCII.GetBytes(FormsAuthentication.HashPasswordForStoringInConfigFile(sKey, "md5").Substring(0, 8));
            provider.IV = Encoding.ASCII.GetBytes(FormsAuthentication.HashPasswordForStoringInConfigFile(sKey, "md5").Substring(0, 8));
            MemoryStream stream = new MemoryStream();
            CryptoStream stream2 = new CryptoStream(stream, provider.CreateDecryptor(), CryptoStreamMode.Write);
            stream2.Write(buffer, 0, buffer.Length);
            stream2.FlushFinalBlock();
            return Encoding.Default.GetString(stream.ToArray());
        }
 
 public static string Encrypt(string Text, string sKey)
        {
            DESCryptoServiceProvider provider = new DESCryptoServiceProvider();
            byte[] bytes = Encoding.Default.GetBytes(Text);
            provider.Key = Encoding.ASCII.GetBytes(FormsAuthentication.HashPasswordForStoringInConfigFile(sKey, "md5").Substring(0, 8));
            provider.IV = Encoding.ASCII.GetBytes(FormsAuthentication.HashPasswordForStoringInConfigFile(sKey, "md5").Substring(0, 8));
            MemoryStream stream = new MemoryStream();
            CryptoStream stream2 = new CryptoStream(stream, provider.CreateEncryptor(), CryptoStreamMode.Write);
            stream2.Write(bytes, 0, bytes.Length);
            stream2.FlushFinalBlock();
            StringBuilder builder = new StringBuilder();
            foreach (byte num in stream.ToArray())
            {
                builder.AppendFormat("{0:X2}", num);
            }
            return builder.ToString();
        }

额,重点是你看了C#代码了么,有些定义类中,根本不存在无法引用。
如果明白自己的功能需求,何必硬要在网上百度来的C#代码进行PHP转换,倒不如自己思考用PHP写。
直接问需求是什么好了。
\Yii::$app->security->encryptByPassword/decryptByPassword和你需要的功能类似,如果只是跟你一样的需求做加密解密,这两个函数应该跟你的功能类似。
但是不保证这两组函数能够解密加密你提供的C#加密解密得到的编码。
因为就你提供的这组加解密函数来看,无法确定其采用的加解密算法(DES也有好几种变形),无法确定采用何种算法的情况下PHP函数要能和C#打通只能自己慢慢试了..

更新数据表的结构缓存[2.0]

GraceKeo阅读(79)

配置db组件的时候设置了enableSchemaCache为true开启了缓存,我现在修改了某个表的结构,要如何更新这个表的缓存呢。现在我是用Cache组件的flush方法吧所有的缓存都删除一下。但这样觉得不太好,有没有只删除某个表的缓存或者只删除数据表结构缓存的。

Yii::$app->db->schema->refresh(); flush all the schema cache
Yii::$app->db->schema->refreshTableSchema($tableName); clear the particular table schema cache

Yii2-admin扩展的menu的高级使用[2.0]

Tinapony阅读(79)

据说可以实现 “不同角色都有自己的菜单” ,请使用过的指导下,是需要怎么设置还是?

我现在创建的菜单就全角色都一样没区别

仅供参考,这是我自己实现的menu里面用来检查权限的方法
输出菜单前先判断当前用户是否有权限。
或者,给每类权限都建立一个菜单,输出对应的菜单。
它的menu没有详细去看,我目前使用的方法是直接echo菜单出来,echo前判断下当前用户是否有权限。
或许menu里是自动会判断权限问题,而你的配置中是全部角色权限都一样,所以看到的都一样。
mark mark

关于composer报错[2.0]

Cleverhope阅读(80)

包的地址:

https://packagist.org/packages/newerton/yii2-fancybox

github地址:

github.com/newerton/yii2-fancybox

包的说明:

php: >=5.4.0
yiisoft/yii2: *
bower-asset/fancybox: @stable
bower-asset/jquery-mousewheel: ~3.1.3

我的 composer.json 文件写入如下:

    "require": {
        "php": ">=5.4.0",
        "yiisoft/yii2": ">=2.0.4",
        "yiisoft/yii2-bootstrap": "*",
        "yiisoft/yii2-swiftmailer": "*",
        "kartik-v/yii2-widget-datepicker": "dev-master",
        "bower-asset/fancybox": "@stable",
        "bower-asset/jquery-mousewheel": "~3.1.3"
    },

composer install之后:

Loading composer repositories with package information
Installing dependencies <including require-dev>
Your requirements could not be resolved to an installable set of packages.

	Problem 1
		- The requested package bower-asset/fancybox could not be found in any version, there may be a typo in the package name.
	Problem 2
		- The requested package bower-asset/jquery-mousewheel could not be found in any version, there may be a typo in the package name.

Potential causes:
	- A typo in the package name
	- The package is not available in a stable-enough version according to your minimum-stability setting

		see <https://groups.google.com/d/topic/composer-dev/_g2ASeIFlrc/discussion> for more details.

Read <http://getcomposer.org/doc/articles/troubleshooting.md> for further common problems.		

我想知道,为什么出这个错误以及怎么解决?不胜感谢!

提示包没找到,具体原因没看出来。
安装yii时有个命令是:
不知道可与这个有关
还有人是这样解决的:
更新了一下composer版本(命令:composer selfupdate),
删除缓存后OK了。
composer.json 裡面改 require 應該不能用 composer install
composer install 應該是修改 composer.lock 時才會去抓
但composer 提示好像不太一樣 (應該不是這個問題)
我剛剛下載過是可以的
不然你 composer global update 重新過濾一次
composer update 一次看看
或者 composer 本身版本過舊 可以先升級版本

Yii2.0验证码问题[2.0]

youthhope阅读(78)

public function actions()
{
    return [
          'captcha' => [
            'class' => 'yii\captcha\CaptchaAction',                 
            'fixedVerifyCode' => substr(mt_rand(1000,9999),0,4),//直到加了这个代码就出问题了
            'minLength' => 4,
            'maxLength' => 4,                
        ],
        'error' => [
            'class' => 'yii\web\ErrorAction',
        ],
    ];
}

本来一切正常,字母显示4个,能正常验证登录。
为了降低验证码难度,想改成4个数字,添加了这行代码
'fixedVerifyCode' => substr(mt_rand(1000,9999),0,4),
能正常显示4个数字了,但是输入正确的验证码后,就是提示验证码错误,这个该怎么排查原因?

使用 fixedVerifyCode 之后, 并没有写 session.
也就是说, 使用了 fixedVerifyCode 之后 生成验证码的时候直接返回了 fixedVerifyCode 的值, 验证的时候 又是拿你输入的 和 fixedVerifyCode的值做对比.. 而你的fixedVerifyCode 每次都变.
你看 fixedVerifyCode 注释, 讲的很清楚, 通常用在自动化测试 方便复制验证码的场景下使用.
非要使用四位数字的话, 继承并重写一下 yii\captcha\CaptchaAction 类里面的 生成验证码的策略吧.
“通常用在自动化测试 方便复制验证码的场景下使用”,不懂这句话是什么意思,求大神讲解。

问下如果yii2框架文件里头没有.bowerrc和.gitignore会不会造成什么问题?[2.0]

Hazelseagull阅读(69)

yii2里的.bowerrc和.gitignore没有会不会带来什么问题?

出了点问题把服务器上的yii重新从本地上传了,发现本地的.bowerrc和.gitignore(就最原始的basic目录下的这2个)怎么都上传不上去,然后我运行服务器上的代码,还是可以正常执行的,所以想问下这2个文件是做什么用的,没有的话,会不会带来什么问题?

.gitignore 是使用 Git 开发时,用于忽略不必要提交的文件,比如忽略程序自动产生的临时文件。
.bowerrc 是使用 Bower 的一个配置文件。
你的服务器可是 linux ?如果是的话,不是上传不了,是已经上传了,只不过是因为名称前有一个小点 .,被服务器隐藏了。linux 下名称前加个小点可用于隐藏文件。
这两个文件上传不到服务器也不要紧。

Yii2中如何让图片不显示图片名而是显示图片[2.0]

littlehappy阅读(77)

数据库里存的图片字段为:pic 格式是:C:\xampp\htdocs\weidu\v1.weidu.com/files/case02.jpg
index.php页面:
如何让图片显示,不是显示图片名,而是显示图片

你这个路径应该只有上传图片的那台设备上能看到..
看你在你的 folder 存甚麼路徑
從 web 下 的 /files/case02.jpg
好问题,没有标注功能,特来标记一下。
以下情况为数据库pic字段存的是图片文件名
经测试,可以使用
另外,DetailView内匿名函数不可用

关于模板的缩写[2.0]

Kindpony阅读(81)

<?= Html::encode($message) ?>
这种写法比较古老,是一种缩写形式。
我看了下 我的php.ini 配置 short_open_tag = off
但是 竟然在YII 下 正常运行
感觉好奇怪,

你们不感觉奇怪么
求大姐 大哥 解释下。

官網寫的~~PHP5.4之後 都是可執行的
http://php.net/manual/en/ini.core.php

帮忙改一下,路径老是出错[2.0]

CGfrog阅读(81)

modules\article\views\admin\action.php代码

<script>
    function checked($id){
        var vals = $("#name").val();
        var id=$id;
        $.ajax({
            type:'post',
            url:"<?= yii\helpers\Url::to(['admin/up']) ?>",路径老是出错
            data:{name:vals,id:id},

            success:function(msg){
                alert(msg);
                //$("#name").val(vals);
            }
        });
    }
</script>

  <?= app\widgets\GridView::widget([
    'dataProvider' => $dataProvider,
    'filterModel' => $searchModel,
    'columns' => [
       ['class' => 'yii\grid\CheckboxColumn'],
       'title',
        [
            'attribute' => 'cate',
            'format' => 'raw',
            'value' => function($model){
                return Html::dropDownList("cates[{$model->id}]",$model->cate,\common\models\Article::$cates,['id'=>'name','onchange' =>"checked($model->id)"]) ;
            }
        ],
      [
            'class' => 'app\widgets\ActionColumn',
            'template' => '{update} {view} {delete}',
       ],
    ]

])?>

modules\article\controllers\AdminController.php代码,我建了一个up方法,想通过它来修改ajax传过来的值

   public function actionUp(){
        
    }

请各位大神帮忙解决一下,哪里有问题,控制文件里帮忙完善起来。

你说的路径出错是报的是 404还是400。如果是400,提交的数据无法被验证的话,那无关路径,可能是yii本身开启了 csrf,只需关闭 csrf认证,或在ajax那里提交csrf 就可以了。
关闭方法,在你的 AdminController.php 里加入
你可以参考这个:http://www.yiichina.com/tutorial/449
<?= Url::to([‘admin/up’]) ?>
use yii\helpers\Url; 命名空间加到顶部
代码复制出来看下
这是异步调用 返回的是json 打印不出来的
admin/up&name=1&id=2 这个url访问看下
你访问的url复制出来看下
var_dump(‘11111111111111111111111111111111111111111111111111’); 改成 echo 1;die;

save方法返回true,但是为什么数据并保存?[2.0]

Neodolphin阅读(76)

学习数据库保存中遇到了一个问题,控制器里的代码如下:

$entry = new EntryForm;
//如果是Post请求提交
if(Yii::$app->request->getIsPost()){
    //表单模型设置属性为post值
    $entry->setAttributes(Yii::$app->request->post());
    //表单模型数据验证
    if ($entry->validate()) {
        //正确
        $result = $entry->save();
        var_dump($entry->attributes);
    } else {
        //返回错误提示
        var_dump($entry->getErrors());
    }
}else{
    //如果不是Post请求,正常显示模板
    return $this->render('entry',['model'=>$entry]);
}

最后能返回插入的id和数据,数据表里面相应的字段为空,只有id。

帖上EntryForm的代码:

<?php
namespace app\models;

use yii\db\ActiveRecord;

class EntryForm EXTENDS ActiveRecord{

    public $name;
    public $email;

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

    public function rules()
    {
        return [
            [['name','email'],'required','message'=>'请填写!'],
            ['email','email','message'=>'邮箱格式不正确!'],
        ];
    }

}

这里有问题,2.0的表前缀是`
{{%user}}

登录

找回密码

注册