草庐IT

php - 如何在 Yii 中使用 beforeAction 或 slug 麻烦

Yii-绝地武士!我正在处理一些旧的Yii项目,必须向它们添加一些功能。Yii是一个非常合乎逻辑的框架,但它有一些我无法理解的东西。可能我还没有了解Yii-way。因此,我将逐步描述我的问题。对于不耐烦的人-最后简短提问。简介:我想将人类可读的URL添加到我的项目中。现在URL看起来像:www.site.com/article/359我希望它们看起来像这样:www.site.com/article/how-to-make-pretty-urls非常重要:旧文章必须在旧格式URL上可用,而新文章必须在新URL上可用。第1步:首先,我更新了config/main.php中的重写规则:'/'

php - Yii 模型 : Username rule allow a-z_-

我如何在YiiFramework中制定规则以在用户名字段中只允许字符a-z、下划线和破折号?谢谢 最佳答案 您应该能够使用manual中概述的match/pattern规则:publicfunctionrules(){returnarray(array('username','required'),array('username','match','not'=>true,'pattern'=>'/[^a-zA-Z_-]/','message'=>'Invalidcharactersinusername.',),);}这个未经测试的代

php - Yii - 从自定义 Controller 类继承 - 未找到

classSomeControllerextendsController{publicfunctionactionIndex(){echo'Thisissomecontroller';}}classAnotherControllerextendsSomeController{publicfunctionactionIndex(){echo'Thisisanothercontroller';}}这个有效:index.php?r=some但是……index.php?r=another说:PHPwarninginclude(SomeController.php):failedtoopenst

php - 无法在 Yii 中看到日志文件

我无法在Yii框架中看到日志文件。默认情况下,它保存在“protected/runtime”中。这是我在main中的配置:'log'=>array('class'=>'CLoCFileLogRoutegRouter','routes'=>array(array('class'=>'CFileLogRoute','levels'=>'error,warning,info','categories'=>'system.*',))),这就是我记录的方式:Yii::log("IndexCheckout","profile",'system.web.CController');Yii::trac

php - 在 Yii2 中运行一个 cron

我正在使用yii2的高级模板应用程序,我想创建一个cron。在谷歌搜索主题时我只能找到很少的信息,到目前为止发现cron作业应该放在控制台文件夹中。我的结构:backend/...console/models/Subscriptions.php//mycustomtablemodel...controllers/TimelineController.php...我不知道从现在去哪里或如何进行?如何运行cron?LAMP环境。 最佳答案 在你的app\console\controllers\SampleControllerclassS

php - 如何在 Yii2 中使用 Yii::$app->security->encryptByKey() 保存加密数据

这是模型。publicfunctiongenCode($width=15){$inputKey=$this->password();$string=Yii::$app->security->generateRandomString($width);$this->_encrypted=Yii::$app->security->encryptByKey($string,$inputKey);//$decrypted=Yii::$app->security->decryptByKey($encrypted,$inputKey,$info=null);return$this->_encrypt

php - 如何转换为在 View 中使用 Yii CDataProvider?

我正在尝试学习Yii,并查看了Yii文档,但仍然没有真正理解它。我仍然不知道如何在Controller和View上使用CDataProvider来显示View上可用的所有博客文章。任何人都可以根据以下内容提出建议或举个例子:我的PostController中的actionIndex:publicfunctionactionIndex(){$posts=Post::model()->findAll();$this->render('index',array('posts'=>$posts));));View,Index.php:除了执行上述操作,任何人都可以建议如何使用CDataProv

php - Yii2 同一模型的多个实例

我想在我的Controller中获得相同模型的多个实例。我看到了thiswikiforYii1.1并尝试这样做,但在我的代码中,只有表单中的最后一个实例是从Controller访问的,我的代码在这里(我用错误和变量值注释了代码):$model=newPerson(['scenario'=>'create_update']);$contractDate=newDatePart();//DatePartismyownclass$contractExpirationDate=newDatePart();//DatePartismyownclassif($model->load(Yii::$a

php - 在 yii2 基本应用程序的供应商文件夹中找不到 Bower 文件夹

我下载了一个基本的yii2应用程序。然后推送到git。但是在其他电脑上,我使用Composer安装了所有依赖项。但是我现在没有bower文件夹所以出现错误:Thefileordirectorytobepublisheddoesnotexist:C:\xampp\htdocs\jumpbyte-site\vendor\bower/jquery/dist'我的composer.json文件具有以下依赖项:"require":{"php":">=5.4.0","yiisoft/yii2":"*","yiisoft/yii2-bootstrap":"*","yiisoft/yii2-swift

php - 使用 Yii2 过滤占位符

关闭。这个问题需要更多focused.它目前不接受答案。想改进这个问题吗?更新问题,使其只关注一个问题editingthispost.关闭7年前。Improvethisquestion有谁知道如何在Yii2Framework的Gridview过滤器上实现占位符或工具提示?我需要一些对用户来说很突出的东西,让他们知道文本框实际上是一个搜索过滤器。期待听到回应。