在Yii 1.1中,此代码适用于默认排序:
$dataProvider = new CActiveDataProvider('article',array(
'sort'=>array(
'defaultOrder'=>'id DESC',
),
));
Run Code Online (Sandbox Code Playgroud)
如何在Yii2中设置默认排序?
尝试下面的代码,但没有结果:
$dataProvider = new ActiveDataProvider([
'query' => $query,
'sort' => ['defaultOrder'=>'topic_order asc']
]);
Run Code Online (Sandbox Code Playgroud) 如何使一个dropdown在yii2使用activeform和模式?由于所有方法都已改变yii2,如何在新的方法中完成?
我安装了最新版本(1.0.0.稳定版)的作曲家,在我的Yii2项目中输入了这个:
php composer.phar update
它给了我这个错误:
[ReflectionException]类Fxp\Composer\AssetPlugin\Repository\NpmRepository不存在
[ErrorException]声明Fxp\Composer\AssetPlugin\Repository\AbstractAssetsRepository :: whatProvides()应与Composer\Repository\ComposerRepository :: whatProvides(Composer\DependencyResolver\Pool $ pool,$ name,$ bypassFilters = false)兼容
有人可以帮我解决这个问题吗?
这是我的composer.json
{
"name": "yiisoft/yii2-app-advanced",
"description": "Yii 2 Advanced Project Template",
"keywords": ["yii2", "framework", "advanced", "project template"],
"homepage": "http://www.yiiframework.com/",
"type": "project",
"license": "BSD-3-Clause",
"support": {
"issues": "https://github.com/yiisoft/yii2/issues?state=open",
"forum": "http://www.yiiframework.com/forum/",
"wiki": "http://www.yiiframework.com/wiki/",
"irc": "irc://irc.freenode.net/yii",
"source": "https://github.com/yiisoft/yii2"
},
"minimum-stability": "stable",
"require": {
"php": ">=5.4.0",
"yiisoft/yii2": ">=2.0.6",
"yiisoft/yii2-bootstrap": "*",
"yiisoft/yii2-swiftmailer": "*",
"kartik-v/yii2-widget-fileinput": "@dev",
"golonka/bbcodeparser": "^2.2"
},
"require-dev": {
"yiisoft/yii2-codeception": "*",
"yiisoft/yii2-debug": "*",
"yiisoft/yii2-gii": "*",
"yiisoft/yii2-faker": "*" …Run Code Online (Sandbox Code Playgroud) 如何在Yii2中启用干净的URL.我想删除index.php和'?' 来自url参数.需要在Yii2中编辑哪个部分?
我正在通过作曲家更新我的yii2,然后又回到旧的测试版.
这是我作曲家的错误:
Loading composer repositories with package information
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.
Problem 1
- The requested package bower-asset/jquery could not be found in any version, there may be a typ
o 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 setti
ng
see <https://groups.google.com/d/topic/composer-dev/_g3ASeIFlrc/discussion> for more details.
Read <http://getcomposer.org/doc/articles/troubleshooting.md> …Run Code Online (Sandbox Code Playgroud) 在yii2 gridview中,我有这个代码:
<?php echo GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'columns' => [
['class' => 'yii\grid\SerialColumn'],
[
'label' => 'bla',
'format' => 'url',
'value' => function ($data) {
return Html::url('site/index');
},
],
['class' => 'yii\grid\ActionColumn'],
],
]); ?>
Run Code Online (Sandbox Code Playgroud)
在网格视图中,使用url地址生成文本.
/学术界 - 新/高级/管理/网站/指数
网址工作正常,但如何为链接设置文字?
我这样做:
$students = Student::find()->all();
return $this->render('process', array('students' => $students));
Run Code Online (Sandbox Code Playgroud)
然后在视图中:
foreach($students as $student)
{
echo $student->name . ', ';
echo $student->getQuizActivitiesCount(); ?> <br /> <?php
}
Run Code Online (Sandbox Code Playgroud)
我想看看正在执行的SQL查询.学生"有很多"测验活动,查询表现完美,但我需要查看原始SQL.这可能吗?
我想从控制器发送参数到布局(即main.php).但是我无法在main.php中获得参数
我试过了:
控制器代码:
$this->render('index',array('param' => $paramValue));
Run Code Online (Sandbox Code Playgroud)
这就是我试图在布局中得到这个的方式.main.php
$this->param (如yii 1)$param但我无法在布局中获得参数值.谁能告诉我怎么做?
yii2 ×10
php ×6
composer-php ×2
yii ×2
activerecord ×1
clean-urls ×1
gridview ×1
logging ×1
sql ×1