我有一个TextBox,但我找不到任何来源解释当按下按钮时如何调用函数.
public Simple()
{
Text = "Server Command Line";
Size = new Size(800, 400);
CenterToScreen();
Button button = new Button();
TextBox txt = new TextBox ();
txt.Location = new Point (20, Size.Height - 70);
txt.Size = new Size (600, 30);
txt.Parent = this;
button.Text = "SEND";
button.Size = new Size (50, 20);
button.Location = new Point(620, Size.Height-70);
button.Parent = this;
button.Click += new EventHandler(Submit);
}
Run Code Online (Sandbox Code Playgroud)
一些消息来源告诉我使用一个函数,但我不明白它是如何被调用的.
我在子父关系中有一个User和一个Role模型,如下面的代码所示.会发生什么是我可以通过父母访问孩子,但反之亦然.访问子角色($ user-> role)只能获得ID.角色列在角色表上有一个外键,但相反的方法不起作用.基本上,$ role包含所有用户$ user-> role不显示用户的角色,只显示他的id
Laravel-Debugbar还显示用户不执行额外查询,而角色则执行.
用户表
id
name
email
password
remember_token
client
role
created_at
updated_at
角色表
id
name
display_name
description
created_at
updated_at
用户模型
namespace App;
use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Database\Eloquent\Model;
use Laratrust\Traits\LaratrustUserTrait;
use App\Client;
use App\Role;
use App\Permission;
class User extends Authenticatable
{
use LaratrustUserTrait;
use Notifiable;
protected $fillable = [
'name', 'email', 'password','role',
];
public function client(){
return $this->hasOne('App\Client', 'client');
}
public function role(){
return $this->belongsTo('App\Role')->withDefault();
}
}
Run Code Online (Sandbox Code Playgroud)
榜样
namespace App;
use Laratrust\Models\LaratrustRole;
use …Run Code Online (Sandbox Code Playgroud) public int a{
get;
set{
if (value <= b)
a = value;
if (value > b)
a = b;
}
}
Run Code Online (Sandbox Code Playgroud)
在上面的例子中是否有可能避免让身体得到,尽管它是一个简单的回归a?