我想使用路由将查询字符串添加到URL的末尾.我如何在Global.asax中执行此操作?
routes.MapRoute(
"Detail",
"{controller}/{action}/{id}/{name}",
new
{
action = "Detail",
name = UrlParameter.Optional,
// it is possible to add here query string(s) ?
},
new[] { "MyProject.Controllers" }
);
Run Code Online (Sandbox Code Playgroud)
例如,实际网址包含:
www.mysite.com/MyController/Detail/4/MyValue
Run Code Online (Sandbox Code Playgroud)
但我想生成类似的东西:
www.mysite.com/MyController/Detail/4/MyValue?ref=test&other=something
Run Code Online (Sandbox Code Playgroud) 目前,我正在使用:
DB::select('select * from users ');
Run Code Online (Sandbox Code Playgroud)
但现在我在http://laravel.com/docs/4.2/queries上阅读
关于:
$users = DB::table('users')->get();
Run Code Online (Sandbox Code Playgroud)
两者都回馈相同。两者之间有什么不同吗?
在文档中确实指出: Note: The Laravel query builder uses PDO parameter binding throughout to protect your application against SQL injection attacks. There is no need to clean strings being passed as bindings.
对于第二种方法。这是否意味着第一种方法无法保护您免受SQL注入的侵害?第二种方法更好吗?两者都以不同的方式返回结果,对吗?
我可以对此进行一些解释吗?
我正在尝试将数据导出到 excel,但似乎无法正常工作。我正在使用:http : //www.maatwebsite.nl/laravel-excel/docs
我正在尽可能多地关注文档。所以我有这个视图,我试图在 excel 中获得它。该文档告诉我:
$sheet->loadView('folder.view');
Run Code Online (Sandbox Code Playgroud)
所以我这样做了,并且(当然)我收到一个错误,说视图中的变量没有被拒绝,因为我没有将变量传递到视图中。所以我再次阅读了文档,它说:
或者,您可以使用与 Laravel 视图相同的 with() 方法。
用一个基本的with()例子。
所以现在我的控制器功能中有这个:
public function something(){
$something2='';
$something='';
Excel::create('Laravel Excel', function($excel) {
$excel->sheet('Excel sheet', function($sheet) {
$sheet->loadView('something')->with('something',$something)
->with('something2',$something2);
$sheet->setOrientation('landscape');
});
})->export('xls');
}
Run Code Online (Sandbox Code Playgroud)
现在我在控制器中收到一个错误:
未定义的变量 $something
所以我不知道会出什么问题。我仍然保持积极的态度,并认为这会很容易,比如实际上没有声明 $something,所以我从 excel 导出中删除了它。然后它给了我错误:
未定义的变量 $something2
在此之后,我知道还有其他问题。由于两者都不是根据 excel 创建“定义”的。所以我尝试了一些新的东西。在 excel 创建中声明两个变量。尽管在声明变量和创建 excel 之间有更多代码。所以这行不通。所以代码是这样的:
$something2='';
$something='';
//more code
if($check==true){
Excel::create('Laravel Excel', function($excel) {
Run Code Online (Sandbox Code Playgroud)
所以我还是卡住了。
这里出了什么问题?我误解了这个excel创作的东西吗?
我似乎无法弄清楚如何在 Laravel scout 中的 1 个查询中的 2 个表中进行搜索。出于目前不重要的特定原因,我不想只运行原始查询。现在我有这个要搜索:
我的关系:
namespace App;
use Laravel\Scout\Searchable;
class Users extends Model
{
use Searchable;
public function searchableAs(){
return 'users_index';
}
public function toSearchableArray(){
return $this->toArray();
}
public function originalUser(){
return $this->belongsTo(OriginalUser::class);
}
}
Run Code Online (Sandbox Code Playgroud)
这是控制器:
use App\OriginalUser;
use App\Users;
use App\Groups;
class SomeController extends Controller{
public function index(){
$group = Group::where('group_id',1)->first();
return Users::search('something')->where('group_id',$group->id)->get();
}
}
Run Code Online (Sandbox Code Playgroud)
现在这将返回在其中一列中具有“某物”的用户,如下所示:
[
{
"id": "1",
"original_user_id": "1",
"username": "something"
"original_user": {
"id": "1",
"username":"test"
}
}
]
Run Code Online (Sandbox Code Playgroud)
但我需要我的代码也返回这条记录:
[
{ …Run Code Online (Sandbox Code Playgroud) 我想从我的oracle数据库中的查询中获取结果并将其放在gridview中.现在我的问题是,我不知道如何在gridview中输出它.我正在使用工具箱中的gridview,我的oracle连接正在运行.我也有正确的SELECT查询,我可以在列表框中输出.我只是不知道如何在gridview中执行此操作.我找了它,我遇到了这个:如何用mysql填充gridview?虽然这对我没有帮助.
如何在gridview中输出它,使其看起来与oracle数据库中的普通表完全相同?
我应该使用什么以及如何使用?
这是我的代码:
public void read()
{
try
{
var conn = new OracleConnection("")
conn.Open();
OracleCommand cmd = new OracleCommand("select * from t1", conn);
OracleDataReader reader = cmd.ExecuteReader();
DataTable dataTable = new DataTable();
while (reader.Read())
{
var column1 = reader["vermogen"];
column = (column1.ToString());
listBox1.Items.Add(column);
}
conn.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
Run Code Online (Sandbox Code Playgroud) 我试图orWhere根据变量的数量在查询中获取一些子句,但是我现在得到的查询结果不是我需要的。
$names = Input::get('name');
$query = DB::table('table')
->where('name', '=', 'something');
foreach ($naam_categorie as $naam){
$query->orWhere('id',$naam));
}
$query->update(array('value' => 1));
Run Code Online (Sandbox Code Playgroud)
我正在更新一个特定的 where 子句,到value = 1. 如何将其余值设为 0?
这里到底出了什么问题?
当我尝试运行这个应用程序时,它说:"路径不是合法的形式." 这是一个警告,它说有一些问题:"fileSystemWatcher1.IncludeSubdirectories = true;" 当我点击浏览时.当我点击浏览第二个filewatcher时,它完全一样.(我有2个浏览按钮来观看2个目录)我给了filewatchers没有起始路径,但是当我给它们一个起始路径时,它可以工作.我不想那样.请帮我.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
private bool pause = false;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
}
// The lines with performed actions of a file
private void fileSystemWatcher1_Created(object sender, System.IO.FileSystemEventArgs e)
{
if (!pause)
{
listBox1.Items.Add("File Created> …Run Code Online (Sandbox Code Playgroud) 我已经创建了一个 sql 行,类型为:datetime。
日期时间的输入应该是这样的: 2013-02-02 10:13:20
你得到这样的练习: 0000-00-00 00:00:00
现在在 php 中,我使用date("Y-m-d H:i:s");(当前日期和时间)将其插入到我的数据库中。还有其他变量。这些变量被插入,但日期时间行保持不变:0000-00-00 00:00:00
当除日期外的所有内容都有效时,我首先得到了此代码:
$resultaat = $mysqli2->query("INSERT INTO questions (title, description, username, date_made) VALUES ('" . $title . "','" . $description . "', '".$username ."','".date("Y-m-d H:i:s")."')");
Run Code Online (Sandbox Code Playgroud)
但是数据库中的所有信息都会""绕过它们。(这可能导致日期跳到 0000-00-00 00:00:00
现在,当我尝试再次插入其他信息时,它甚至不再插入。我的问题:
0000-00-00 00:00:00?是自动的""吗?"",我怎么能失去它们?编辑:
Nvm 我丢失了""这不是导致插入在第二次尝试时失败的问题。- 为什么我插入一次后就不再插入了?
现在这些并不是真正不同的问题,因为它是关于相同的问题,但这是我的代码,是的,我知道 SQL 注入,我稍后会修复它:
if (isset($_POST['title'])) {
$alles_goed=true;
$description=$_POST['description'];
$title=$_POST['title'];
$username=$_SESSION['username'];
if ($title=''){
$alles_goed=false;
echo'title is empty';
}
if($alles_goed==true){
$resultaat …Run Code Online (Sandbox Code Playgroud) 在 Laravel 中,我刚开始使用模型,并且具有以下数据库结构:
users
id | username | password | group | //(group is the id of the group)
groups
id | groupname |
group_pages
group_id | page_id | create | read | update | delete
pages
id | pagename
Run Code Online (Sandbox Code Playgroud)
我试图检查用户是否可以在他所在的页面上创建/读取/更新/删除。
所以我现在有 4 个模型:Users,Pages,Group_pages和Groups。所以在模型中,我定义了这样的关系:
用户模型:
public function group()
{
return $this->belongsTo('group', 'group', 'id');
}
Run Code Online (Sandbox Code Playgroud)
团体模式:
public function users()
{
return $this->hasMany('users', 'group', 'id');
}
public function group_pages()
{
return $this->hasMany('group_pages', 'group_id', 'id'); …Run Code Online (Sandbox Code Playgroud) 只是关于Laravels验证器的查询.我的网站的用户将在可能大约100MB标记的时间上传文件.
我看过:http://laravel.com/docs/4.2/validation
我的控制器代码如下:
$rules = array(
'file' => 'max:102400'
);
Run Code Online (Sandbox Code Playgroud)
102400相当于100MB,我觉得文档对此不够清楚吗?