现在我的应用程序正在使用gridview列出所有信息,并且它也有分页.当用户单击分页编号然后单击编辑然后保存.它将用户重定向到查看页面.我想做什么来将用户重定向到上一页(带分页号的网址).
yii\bootstrap\BootstrapAsset没有加载bootstrap.js,像"模态"和其他元素不起作用.
class AppAsset extends AssetBundle {
public $basePath = '@webroot';
public $baseUrl = '@web';
public $css = [
/* theme */
'css/site.css',
/* jasny bootstrap */
'public/jasny/css/jasny-bootstrap.min.css',
/* font awesome */
'public/font-awesome-430/css/font-awesome.min.css',
/* font roboto */
'public/fonts/roboto/roboto.css',
/* Data Tables */
'public/datatables/extensions/integration/bootstrap/3/dataTables.bootstrap.css',
];
public $js = [
/* jasny bootstrap */
'public/jasny/js/jasny-bootstrap.min.js',
/* Data Tables */
'public/datatables/datajs.js',
'public/datatables/media/js/jquery.dataTables.min.js',
'public/datatables/extensions/integration/bootstrap/3/dataTables.bootstrap.js',
];
public $depends = [
'yii\web\YiiAsset',
'yii\bootstrap\BootstrapAsset',
];
}
Run Code Online (Sandbox Code Playgroud)
这是图书馆的屏幕,bootstrap.js在那里缺失.
我想在不使用composer的情况下使用Yii2 Framework手动安装Select 2扩展小部件.
我完成了以下步骤,但它不起作用.
1)添加yii2-widget-select2到vendor/yii-soft
2)在我的代码中添加了以下代码yii-soft/extensions.php:
'yiisoft/yii2-widget-select2' => array(
'name' => 'yiisoft/yii2-widget-select2',
'version' => '2.0.3.0',
'alias' =>
array(
'@yii/kartik' => $vendorDir . '/yiisoft/yii2-widget-select2',
),
),
Run Code Online (Sandbox Code Playgroud)
3)以视图形式添加显示:
use kartik\select2\Select2;
<?php echo Select2::widget([
'model' => $model,
'attribute' => 'state_2',
'data' => $data,
'options' => ['placeholder' => 'Select a state ...'],
'pluginOptions' => [
'allowClear' => true,
],
]); ?>
Run Code Online (Sandbox Code Playgroud)
它显示以下错误:
PHP致命错误 - yii\base\ErrorException.找不到类'kartik\select2\Select2'
如何将此sql转换为活动记录查询
SELECT * FROM `base_twitter` WHERE id NOT IN (SELECT base_id from base_followers)
Run Code Online (Sandbox Code Playgroud) 有没有办法重定向到Yii 2中的行为方法登录以外的页面?
我的行为方法内容:
public function behaviors()
{
return [
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
'delete' => ['post'],
],
],
'access' => [
'class' => AccessControl::className(),
'only' => [ 'create','update' ],
'rules' => [
[
'allow' => true,
'actions' => [ 'create'],
'roles' => ['@'],
],
[
'allow' => true,
'actions' => ['logout'],
'roles' => ['?'],
],
],
],
];
}
Run Code Online (Sandbox Code Playgroud)
但它重定向到登录.我需要指定另一个重定向页面或调用:
throw new \yii\web\HttpException(403, 'The requested Item could not be found.');
Run Code Online (Sandbox Code Playgroud) 我想弄清楚是否有可能在highcharts的实际饼图中显示每个饼图的百分比?我的意思是这样的例子:
https://developers.google.com/chart/interactive/docs/gallery/piechart
我有三个数据库表:
产品(id,名称)
product_has_adv(产品,优势,排序,重要)
优势(身份证,文字)
在ProductModel中我定义了这个:
public function getAdvantages()
{
return $this->hasMany(AdvantageModel::className(), ['id' => 'advantage'])
->viaTable('product_has_advantage', ['product' => 'id']);
}
Run Code Online (Sandbox Code Playgroud)
我毫无问题地获得了优势.
但是现在我需要添加一个product_has_advantage.important = 1 clausel,并通过product_has_advantage-table中的sort-columen对优势进行排序.
我如何以及在哪里实现它?
我似乎无法理解战略模式提供的优势.请参阅下面的示例.
//Implementation without the strategy pattern
class Registry {
public function Func1(){
echo 'called function 1';
}
public function Func2(){
echo 'called function 2';
}
}
$client = new Registry();
$client->Func1();
$client->Func2();
//Implementation with strategy pattern
interface registry {
public function printMsg();
}
class Func1 implements registry {
public function printMsg(){
echo 'called function 1';
}
}
class Func2 implements registry {
public function printMsg(){
echo 'called function 2';
}
}
class context {
public function printMsg(Registry $class){
$class->printMsg();
} …Run Code Online (Sandbox Code Playgroud) 我正在使用Yii2做一个小项目.
假设我在视图中具有相同的布局(页眉,页脚)(例如site),除了login.php在此视图中的a.我想在此文件中使用不同的页眉/页脚.我该怎么做才能从此视图文件中删除页眉/页脚.
我只能在不同的视图中更改布局.是否可以在视图的单个文件中更改布局?
我试图运行yii migrate,但它显示以下错误:
create table news-cate ...Exception: SQLSTATE[42000]: Syntax error or access violation: 1075 Incorrect table definition; there can be only one auto column and it must be defined as a key
The SQL being executed was: CREATE TABLE `news-cate` (
`news-id` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
`cate-id` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY
Run Code Online (Sandbox Code Playgroud)
这是我的代码:
class m150821_083020_create_newscate_table extends Migration
{
public function safeUp()
{
$this->createTable('news-cate', [
'news-id' => $this->primaryKey(),
'cate-id' => $this->primaryKey(),
]);
$this->addForeignKey("fk_news_cate_nid", "news-cate", "news-id", "news", "id", …Run Code Online (Sandbox Code Playgroud) yii2 ×8
php ×3
javascript ×2
activerecord ×1
composer-php ×1
highcharts ×1
oop ×1
sql ×1
widget ×1
yii ×1