怎么去掉 验证码前面的字母?
$form->field($model, 'verifyCode', ['template' => "{input}\n{hint}\n{error}"])->widget(Captcha::className()..........
打开源码,删除verify code.
我只能说这么多了
设置’template’属性
怎么去掉 验证码前面的字母?
$form->field($model, 'verifyCode', ['template' => "{input}\n{hint}\n{error}"])->widget(Captcha::className()..........
打开源码,删除verify code.
我只能说这么多了
设置’template’属性
这个URL http://admin.demo.com/articletype/index.html?page=2&per-page=1 怎么重写伪静态啊 怎么写他的规则啊 求个样式
articletype/index/2:1.html
articletype/index/page/2/per-page/1.html
http://www.yiichina.com/topic/4327
哎,有现成的,都不会找么…
如题,在yii2中怎么加载一个ico图标
和别的网站一样的处理方式,没啥不一样
ico没有专门的加载吧,就放在根目录就行了吧
利用调试工具看一下资源文件有没有正常加载
现在分类只有一级和二级,知道一级的分类ID,可以查询出所有二级分类ID和名字,但是怎么循环查出每个分类下10条新闻,
现在控制器代码如下:
$minlist = CateUtils::getMinCateList($cid); //获取所有下级栏目ID和名字
foreach ($minlist as $k => $v) {
$sql = "select id,catid,mincate,title from daquan_article where mincate = $k limit 5";
$list['list1'] = Article::model()->findAllBySql($sql);
var_dump($list); //在这里可以每个二级栏目输出10条新闻,但是不知道怎么赋值到views
}
var_dump($list); //这里只能输出第一个二级栏目的10条新闻
大神们帮忙看下,是哪里有问题。谢谢
$list['list1']
修改为
循环外怎么可能直接获得循环内的数据,美术老师教的?
比如有文章表 Article(Id,Category,InsertDate),现在要用SQL找出每种类型中时间最新的前N个数据组成的集合。
@N 就是你要取多少条
需要批量插入学生啊,但是password字段如何搞定?
我想直接在mysql里面插入,密码是怎么加密的?有方法吗?
如果密码可以一样,你就在yii2存一条,然后拷贝出来,
如果不一样,每次都要加密,就直接在程序里操作了,不要直接在mysql了。
如果是安装了yii2-user模块,直接mysql肯定不行,通过程序也很简单:
我配置了三个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目录
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中写迁移脚本,怎么添加普通索引,怎么写注释。
迁移脚本中不为空可以用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
如题,在使用activeform之后,自动引入了js与模板的js相冲突,导致js验证无法生效,虽然没有太大影响,但毕竟是个bug,有什么解决方案吗?
二选一,保留其中一个js。
或者对其中一个进行修改,保证两个同时出现是不冲突。
给你模板的js改个名不就行了吗
我也一样,然后去掉了一个,完美运行
解决冲突的最好方法就是,覆盖!!
我是想update文章表的数据,$model->load(Yii::$app->request->post())
,但是我没有去写一个updateForm这样的验证模型,而是直接用Article模型去load提交的post的数据,然后失败了提示_Failed to set unsafe attribute 'id' in 'app\models\Articles'
.我查了好像要设置scenario,但还是具体还是不知道该怎么办,如果像我这样直接load的该怎么写?
http://www.yiichina.com/topic/5924
之前回答过一次这样的问题 你看下.
你是有怎样的需求需要跳过数据验证呢?