谁一开始就是大神?

PHP 第83页

PHP

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

CGqueen阅读(85)

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

配置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阅读(94)

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

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

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

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

CGfrog阅读(100)

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

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

$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}}

save()时报500错误[2.0]

Noblelovely阅读(90)

在一个ajax发送请求和保存数据的时候报500错误
代码:

$res = new Apptxt();
			   
$res->datetime = time();
$res->appid = 7;
$res->content = "123456";
$res->creater = 7;
$res->isdel = 0;
$res->save();

错误代码

Exception 'ReflectionException' with message 'Class numerical does not exist' 

in C:\xampp\htdocs\coupon\vendor\yiisoft\yii2\di\Container.php:415

Stack trace:
#0 C:\xampp\htdocs\coupon\vendor\yiisoft\yii2\di\Container.php(415): ReflectionClass->__construct('numerical')
#1 C:\xampp\htdocs\coupon\vendor\yiisoft\yii2\di\Container.php(358): yii\di\Container->getDependencies('numerical')
#2 C:\xampp\htdocs\coupon\vendor\yiisoft\yii2\di\Container.php(151): yii\di\Container->build('numerical', Array, Array)
#3 C:\xampp\htdocs\coupon\vendor\yiisoft\yii2\BaseYii.php(344): yii\di\Container->get('numerical', Array, Array)
#4 C:\xampp\htdocs\coupon\vendor\yiisoft\yii2\validators\Validator.php(206): yii\BaseYii::createObject(Array)
#5 C:\xampp\htdocs\coupon\vendor\yiisoft\yii2\base\Model.php(440): yii\validators\Validator::createValidator('numerical', Object(app\models\Apptxt), Array, Array)
#6 C:\xampp\htdocs\coupon\vendor\yiisoft\yii2\base\Model.php(404): yii\base\Model->createValidators()
#7 C:\xampp\htdocs\coupon\vendor\yiisoft\yii2\base\Model.php(184): yii\base\Model->getValidators()
#8 C:\xampp\htdocs\coupon\vendor\yiisoft\yii2\base\Model.php(340): yii\base\Model->scenarios()
#9 C:\xampp\htdocs\coupon\vendor\yiisoft\yii2\db\ActiveRecord.php(416): yii\base\Model->validate(NULL)
#10 C:\xampp\htdocs\coupon\vendor\yiisoft\yii2\db\BaseActiveRecord.php(589): yii\db\ActiveRecord->insert(true, NULL)
#11 C:\xampp\htdocs\coupon\controllers\NrkController.php(219): yii\db\BaseActiveRecord->save()
#12 [internal function]: app\controllers\NrkController->actionEdittxtmsg('0')
#13 C:\xampp\htdocs\coupon\vendor\yiisoft\yii2\base\InlineAction.php(55): call_user_func_array(Array, Array)
#14 C:\xampp\htdocs\coupon\vendor\yiisoft\yii2\base\Controller.php(151): yii\base\InlineAction->runWithParams(Array)
#15 C:\xampp\htdocs\coupon\vendor\yiisoft\yii2\base\Module.php(455): yii\base\Controller->runAction('edittxtmsg', Array)
#16 C:\xampp\htdocs\coupon\vendor\yiisoft\yii2\web\Application.php(84): yii\base\Module->runAction('nrk/edittxtmsg', Array)
#17 C:\xampp\htdocs\coupon\vendor\yiisoft\yii2\base\Application.php(375): yii\web\Application->handleRequest(Object(yii\web\Request))
#18 C:\xampp\htdocs\coupon\web\index.php(12): yii\base\Application->run()
#19 {main}

可能是因为什么,求大腿指教

是不是在Apptxt类里的rules里面给哪个属性加了个数字验证,把number打成了numerical?yii2里面没有内置叫numerical的验证类
粗心该打屁屁,哇咔咔~

如何在index.php里面设style样式[2.0]

Jimnice阅读(88)

我想在index.php中把第一列的宽度设定为100px大小,要怎么写代码
index.php代码如下:

'columns' => [
    ['class' => 'yii\grid\CheckboxColumn'],
    [
        'attribute' => 'sort',
        'format' => 'raw',
        'value' => function($model){
            return Html::textInput("sorts[{$model->id}]", $model->sort, ['style'=>'width:40px']);
        }
    ],
]

请教数据库多条件怎么查询[2.0]

lovequeen阅读(92)

请教下 $model->where([‘type’=>1])->andWhere([‘like’, ‘content’, $keyword]) 还有个条件 create_time > $time 应该怎么写

Accountdoc::find() ->andFilterWhere([‘=’,’nShopID’,$this->nShopID])
可以类似这样写
where([‘>’,’create_time’,$time])
andWhere([‘>’,’create_time’,$time])
用数组啊,可以把数组放进where
最简单的是
where([‘type’=>1,array(‘like’,’content’,$keyword),array(‘>’,’create_time’ ,$time)])
不知道有没有写错额~~你可以试试!

关于composer报错[2.0]

Cleverhope阅读(94)

包的地址:

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

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 类里面的 生成验证码的策略吧.
“通常用在自动化测试 方便复制验证码的场景下使用”,不懂这句话是什么意思,求大神讲解。

登录

找回密码

注册