我有两个数据库表'user'和'role'.我使用Yii framework 2.0 Gii用User模型和UserSearch模型创建CRUD.默认情况下,Gii使用GridView :: widget作为"用户"模型的索引页面.
在UserSearch模型内部的搜索($ params)方法中,我使用以下代码将上述表连接在一起
$query = User::find()->with('role');
Run Code Online (Sandbox Code Playgroud)
查询一切正常.
默认情况下,Gii不包含来自views/user/index.php页面内GridView :: widget中的连接表'role'的数据.通过上面的连接查询,我可以从两个表中检索数据.在views/user/index.php页面中,我使用以下代码注入了GridView :: widget,以便它还包括连接表(角色)中的数据和列名.
<?= GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'columns' => [
['class' => 'yii\grid\SerialColumn'],
'userid',
'username',
'role.role_name',
['class' => 'yii\grid\ActionColumn'],
],
]); ?>
Run Code Online (Sandbox Code Playgroud)
使用GridView :: widget中包含的角色数据'role_name,一切正常.但问题是role_name没有搜索框.GridView :: widget仅为User属性创建搜索框.有没有办法为联接表'role'的属性添加搜索框,因为我还想搜索'role_name'以及User模型的其他属性.
我一直在阅读关于Java中编译时和运行时之间的不同的许多答案.但我还不清楚.一些答案说:编译时间是您(开发人员)正在编译程序或代码的时间段.我的问题是我什么时候编译我的程序或代码?例如:我打开我的IDE,eclipse或netbeans,在不同的类中编写代码,然后单击Run按钮,我的应用程序就会打开.有人可以解释我什么时候在这个示例过程中编译我的程序/代码?或者我在这个示例过程中何时处于编译时阶段?
我是Spring Tool Suite IDE中使用Java Spring Framework开发Web应用程序的新手.当开始一个新项目时,有很多种项目,如Spring Project,Simple Spring Utility Project,Spring VMC Template Project,Spring Roo Project,Static Web Project,Dynamic Web Project和Maven Project.我不知道应该选择哪个项目?有人可以解释一下吗?
学习Yii Framework 2.0我试图从Yii 2.0的文档中使用角色基础访问控制.但是指南文档太短了,我无法完成这个学习.我已将以下代码添加到配置文件中.
'components' => [
'authManager' => [
'class' => 'yii\rbac\DbManager',
],
],
Run Code Online (Sandbox Code Playgroud)
我用以下sql脚本创建了数据库表.
drop table [auth_assignment];
drop table [auth_item_child];
drop table [auth_item];
drop table [auth_rule];
create table [auth_rule]
(
[name] varchar(64) not null,
[data] text,
[created_at] integer,
[updated_at] integer,
primary key ([name])
);
create table [auth_item]
(
[name] varchar(64) not null,
[type] integer not null,
[description] text,
[rule_name] varchar(64),
[data] text,
[created_at] integer,
[updated_at] integer,
primary key ([name]),
foreign key ([rule_name]) references [auth_rule] ([name]) on delete set …Run Code Online (Sandbox Code Playgroud) 在使用Yii框架2.0时,我尝试按照Yii文档使用分页功能和linkpager小部件。
以下是我的控制器。
public function actionIndex()
{
$query = Country::find();
$pagination = new Pagination([
'defaultPageSize' => 5,
'totalCount' => $query->count(),
]);
$countries = $query->orderBy('name')
->offset($pagination->offset)
->limit($pagination->limit)
->all();
return $this->render('index', [
'countries' => $countries,
'pagination' => $pagination,
]);
}
Run Code Online (Sandbox Code Playgroud)
在索引视图中,我使用以下代码。
<?= LinkPager::widget(['pagination' => $pagination]) ?>
Run Code Online (Sandbox Code Playgroud)
现在,我想为另一个模型City添加一个分页功能和LinkPager小部件。在actionIndex()方法中,我遵循现有代码,只需创建一个City对象和一个新Pagination对象,然后将其返回到视图。在视图中,我再次包含LinkPager小部件以及另一个分页变量$ paginationCity。当我单击一个分页号码时,我在URL中看到查询字符串page = xx。我注意到它同时用于Country和City模型。如何在同一页面上使用多个分页?
以下是我从浏览器创建和下载CSV文件的代码段.
$input_array[] = ['????', '????',];
$input_array[] = ['2015-09-30', 'INV-00001',];
/** open raw memory as file, no need for temp files, be careful not to run out of memory thought */
$f = fopen('php://memory', 'w');
/** loop through array */
foreach ($input_array as $line) {
/** default php csv handler **/
fputcsv($f, $line, ',');
}
/** rewrind the "file" with the csv lines **/
fseek($f, 0);
/** modify header to be downloadable csv file **/
header('Content-Encoding: UTF-8');
header('Content-Type: application/csv; charset=UTF-8');
header('Content-Disposition: …Run Code Online (Sandbox Code Playgroud) 通常,当我想从远程存储库更新我的项目时,我使用以下命令行。
git pull -a origin develop
Run Code Online (Sandbox Code Playgroud)
我从我的项目团队成员那里了解到这一点,但我无法在互联网上找到 -a 标志的作用的答案。-a 是什么意思?
我有一个编辑节点表单。当用户输入新值并单击提交来编辑节点时,我首先想取回旧节点,操作该值,然后保存/更新节点。
以下是我的解决方案,但它不起作用。
function custom_module_form_node_form_alter(&$form, FormStateInterface $form_state) {
$editing_entity = $form_state->getFormObject()->getEntity();
if (!$editing_entity->isNew()) {
$form['actions']['submit']['#submit'][] = 'custom_module_node_form_submit';
}
}
function custom_module_node_form_submit($form, FormStateInterface $form_state) {
$editing_entity = $form_state->getFormObject()->getEntity();
$entity = Drupal::entityTypeManager()->getStorage('node')->load($editing_entity->id());
}
Run Code Online (Sandbox Code Playgroud)
在 form_submit 钩子中,我尝试取回旧节点,但已经太晚了,节点已经更新/保存。在 Drupal 8 中更新/保存节点之前,如何取回旧节点并操作该值?
开始使用Laravel 4.2我尝试使用Gmail STMP服务器发送电子邮件.下面是我的app/config/mail.php.
return array(
'driver' => 'smtp',
'host' => 'smtp.gmail.com',
'port' => 465,
'from' => array('address' => 'sample_address@gmail.com', 'name' => 'Sample'),
'encryption' => 'tls',
'username' => 'sample_address@gmail.com',
'password' => 'sample password',
'sendmail' => '/usr/sbin/sendmail -bs',
'pretend' => false,
);
Run Code Online (Sandbox Code Playgroud)
下面是我的PHP代码.
<!-- app/views/emails/welcome.php -->
Mail::send('emails.welcome', 'Laravel Admin', function($msg) {
$msg->from('sample_address@gmail.com', 'Laravel Admin');
$msg->to('sample_receiver@gmail.com');
});
Run Code Online (Sandbox Code Playgroud)
但它不起作用.我已经在我的MAC OSX上配置了我的XAMPP php.ini.它仅在发送普通PHP邮件时有效,而不是SMTP.我在视图页面上从Laravel获得的错误消息是" 异常处理程序错误 ".我想看到更多的错误信息,但我不知道如何获得更多信息.我的代码出了什么问题?我还需要做什么或配置什么?谢谢!
我知道Yii framework 2.0迁移的概念.假设我们生成迁移源代码并运行命令,将根据源代码创建数据库表.是否可以基于现有数据库创建迁移源代码?使用源代码我不是指模型,控制器或CRUD类,而是指迁移源代码.它是某种逆向工程师.