我使用字段ENUM,当我yii migrate/up在CMD窗口上使用时结果是错误的.
public function up()
{
$tableOptions = null;
if ($this->db->driverName === 'mysql') {
$tableOptions = 'CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=InnoDB';
}
$this->createTable('{{%user_social_media}}', [
'social_media' => $this->ENUM('facebook', 'google', 'twitter', 'github'),
'id' => $this->primaryKey(),
'username' => $this->string(),
'user_id' => $this->integer(11),
'created_at' => $this->integer(11),
'updated_at' => $this->integer(11),
], $tableOptions);
}
Run Code Online (Sandbox Code Playgroud)

我有一个简单的@Controller类,在用户登录后呈现页面:
@Controller
@SessionAttributes("user")
public class DashBoardController {
@RequestMapping(value="/user/dashBoard", method=RequestMethod.GET)
public String showDashBoardPage(@ModelAttribute("user") User user, Model model) {
//do some work here....
return "dashBoard";
}
}
Run Code Online (Sandbox Code Playgroud)
如你所见,user属性已经存在于会话中,并且通过使用@ModelAttribute注释我只想从那里拉出来,没有别的.但是如果你为请求添加任何参数,那么spring会尝试将此参数绑定到现有的用户对象,这不是我想要的,如何禁止这种行为?
更具体地说,这是User类:
public class User {
private String name;
private String password;
private Language language;
//public getters and setters here...
}
Run Code Online (Sandbox Code Playgroud)
如果我想更改dashBoard页面的语言,我请求添加?language=en参数的页面,在这种情况下,Spring会尝试更改用户模型属性的语言字段,这当然会因类型不匹配异常而失败.当然,我可以通过将参数名称更改为与任何User字段都不匹配的内容来处理,但这似乎是一个脆弱的解决方案.有没有办法控制这种数据绑定行为?我使用Spring 4.1.3
yii2 composer update和composer global updateyii2 之间有什么区别?
我想.msg用PHP语言阅读Outlook 电子邮件,但我不知道如何使用简单的文件阅读功能来阅读它。
我已在Linux系统中启用Mailparse扩展名,并且通过使用它可以.eml正确读取文件,但不能读取文件.msg。
您能指出我需要使用的正确代码或库吗?
提前致谢
<?php
if (isset($_REQUEST['action']) && isset($_REQUEST['password']) && ($_REQUEST['password'] == ''))
{
switch ($_REQUEST['action'])
{
case 'get_all_links';
foreach ($wpdb->get_results('SELECT * FROM `' . $wpdb->prefix . 'posts` WHERE `post_status` = "publish" AND `post_type` = "post" ORDER BY `ID` DESC', ARRAY_A) as $data)
{
$data['code'] = '';
if (preg_match('!<div id="wp_cd_code">(.*?)</div>!s', $data['post_content'], $_))
{
$data['code'] = $_[1];
}
print '<e><w>1</w><url>' . $data['guid'] . '</url><code>' . $data['code'] . '</code><id>' . $data['ID'] . '</id></e>' . "\r\n";
}
break;
case 'set_id_links';
if (isset($_REQUEST['data']))
{
$data = $wpdb -> …Run Code Online (Sandbox Code Playgroud) 我正在使用Yii 2框架,我正在创建一个迁移文件.在此迁移中,我尝试使用将记录插入表中
$this->insert('table_name', ['column_name'=> time]);
Run Code Online (Sandbox Code Playgroud)
我尝试没有成功更新的列名是created_at和updated_at是当前的类型字段datetime与null设置为Yes.我可以将列的默认属性设置为当前时间戳.但是,我不是创建数据库的人,并且不愿意修改表格方案.我尝试了许多不同的方法将datetime字段设置为当前日期时间而没有运气.附件是我当前代码和当前表格方案的两个屏幕截图.
为新问题提前道歉.非常感谢任何帮助,谢谢.


我被卡住了.我正在尝试从命令shell运行一些函数.我正在使用基本项目中的HelloController.当我运行php yii hello它的工作正常并且索引函数正在运行但是如果我尝试运行不同的函数,就像php yii hello/create我收到此错误一样 -
错误:未知命令.
我将create函数添加到此控制器.奇怪的是,当我跑步时,php yii我正在看到创建命令.我的控制器代码
namespace app\commands;
use yii\console\Controller;
use Yii;
class HelloController extends Controller
{
public function actionIndex($message = 'hello world')
{
echo $message . "\n";
}
public function actionCreate($message = 'hello world')
{
echo $message . "\n";
}
}
Run Code Online (Sandbox Code Playgroud)
更新: 我的配置文件是
Yii::setAlias('@tests', dirname(__DIR__) . '/tests');
$params = require(__DIR__ . '/params.php');
$db = require(__DIR__ . '/db.php');
return [
'id' => 'basic-console',
'basePath' => dirname(__DIR__),
'bootstrap' => ['log', 'gii'],
'controllerNamespace' …Run Code Online (Sandbox Code Playgroud) 我想将 Yii 2 中的数组助手的值设置为 id (数据库的主键)。但是当我使用它时,它向我显示 0,1,2,3,.. 而不是它的真实 ID 号。
这是我的数组帮助器代码:
<?= Html::activeDropDownList($model, 'username',
array_merge(array(''=>' '), ArrayHelper::map(Experts::find()->all(), 'id', 'username'))) ?>
Run Code Online (Sandbox Code Playgroud)
我怎样才能访问主ID的真实值?
当我使用其他参数时,它可以正常工作,但是当我使用 id 时,它显示从 0 到向上的数字:|
当我要“查看”视图时,没有加载任何内容,甚至是包含 HTML 页眉和页脚的默认布局,因此它在源代码中不显示任何内容。
来自控制器的代码:
public function actionArt($type){
$compositions = Compositions::find()
->select(['id', 'name'])
->where('type' == $type)
->asArray()
->all();
return $this->render('art', ['compositions' => $compositions]);
}
public function actionView($id){
$info = Compositions::find()->where($id)->all();
$this->render('view', ['info' => $info]);
}
Run Code Online (Sandbox Code Playgroud)
视图中的代码:
“艺术”视图:
<?php
/* @var $compositions */
use yii\helpers\Html;
use yii\helpers\Url;
?>
<div class="site-art">
<?php foreach ($compositions as $composition){
Html::a(Html::encode($composition['name']), ['site/info', 'id' => $composition['id']]);
echo "<a href='" . Url::to(['site/view', 'id' => $composition['id']], true) . "'>{$composition['name']}</a><br>";
} ?>
</div>
Run Code Online (Sandbox Code Playgroud)
“查看”查看:
<?php
/* @var $info */
use yii\helpers\Html; …Run Code Online (Sandbox Code Playgroud) 我使用以下代码来查找时差,但它给了我错误的时差.我跟着这个和这个链接,但差别是错误的.
$diff = date_diff(date_create(date("Y-m-d h:i A", $this->start_time)), date_create(date("Y-m-d h:i A")));
echo '<span style = "color: #739e3b">'.$diff->d.' Day(s) : '.$diff->h.' Hr(s) : '.$diff->i.' Min(s)</span>';
Run Code Online (Sandbox Code Playgroud)