我是CodeIgniter的新手并完成了我的第一个项目.但是,在我把它放在我的托管网站上之前,我想使用CodeIgniter在config文件夹中提供的routes.php文件来清理URL.
我的网站将使用以下网址加载:
http://fakehost:8888/TheWorksPlumbing/index.php/theWorksPlumbingController/index/home
http://fakehost:8888/TheWorksPlumbing/index.php/theWorksPlumbingController/index/about
http://fakehost:8888/TheWorksPlumbing/index.php/theWorksPlumbingController/index/services
Run Code Online (Sandbox Code Playgroud)
它还将使用以下默认控制器URL加载主页: http://fakehost:8888/TheWorksPlumbing/
但是,我希望网站的每个页面都有一个网址,但无法让它工作.例如,我想:
http://fakehost:8888/TheWorksPlumbing/home
http://fakehost:8888/TheWorksPlumbing/about
http://fakehost:8888/TheWorksPlumbing/services
Run Code Online (Sandbox Code Playgroud)
以下是theWorksPlumbingController控制器文件的代码:
class TheWorksPlumbingController extends CI_Controller {
public function index($page = 'home'){
if ( !file_exists('application/views/'.$page.'.php') ) {
show_404();
}
$this->load->view('templates/header');
$this->load->view($page);
$this->load->view('templates/footer');
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的routes.php文件中的代码不起作用:
$route['default_controller'] = "theWorksPlumbingController";
$route['404_override'] = '';
$route['(:any)'] = "index.php/theWorksPlumbingController/index";
Run Code Online (Sandbox Code Playgroud)
我需要添加或更改以使网站只加载/ home或/ about或/ services?
我最近听说过7.2中的新C#Feature,所以我们现在可以返回值类型的引用(例如int)甚至是值类型的只读引用.所以据我所知,值类型存储在堆栈中.当剩下方法时,它们会从堆栈中删除.那么当方法GetX退出时,int会发生什么?
private ref int GetX()
{
// myInt is living on the stack now right?
int myInt = 5;
return ref myInt;
}
private void CallGetX()
{
ref int returnedReference = ref GetX();
// where does the target of 'returnedReference' live now?
// Is it somehow moved to the heap, because the stack of 'GetX' was removed right?
}
Run Code Online (Sandbox Code Playgroud)
我收到了错误
错误CS8168:无法通过引用返回本地'myInt',因为它不是ref本地(11,24)
那为什么它不起作用?它不起作用只是因为变量无法移动到堆中吗?这是问题吗?如果它们不在堆栈中,我们只能通过引用返回值类型吗?我知道这是两个问题.
第一:ref返回的值类型变量在哪里?堆栈还是堆?(我猜在堆上,但为什么)?
第二:为什么堆栈上创建的值类型不能通过引用返回?
所以这可以编译:
private int _myInt;
private ref int GetX()
{
// myInt is …Run Code Online (Sandbox Code Playgroud) 我已经编写了一些代码来允许在我们的网站上过滤产品,而且我的代码味道非常糟糕.用户可以选择1-*这些过滤器,这意味着我需要特定于该WHERE子句.
我想我正在寻找一种构建lambda表达式的方法,所以对于每个过滤器我都可以"修改"我的WHERE子句 - 但我不确定如何在.NET中执行此操作,并且必须有一种方法.
处于当前状态的代码(实际上是硬编码的,而不是动态的,添加更多过滤器选项会很麻烦).
public static class AgeGroups
{
public static Dictionary<string, int> Items = new Dictionary<string, int>(){
{ "Modern (Less than 10 years old)", 1 },
{ "Retro (10 - 20 years old)", 2 },
{ "Vintage(20 - 70 years old)", 3 },
{ "Antique(70+ years old)", 4 }
};
public static IQueryable<ProductDTO> FilterAgeByGroup(IQueryable<ProductDTO> query, List<string> filters)
{
var values = new List<int>();
var currentYear = DateTime.UtcNow.Year;
foreach (var key in filters)
{
var …Run Code Online (Sandbox Code Playgroud) 我有一个GridViewColumn与 a HeaderTemplate,其中有一个Image和 a TextBlock。当用户将鼠标悬停Image在我正在更改其不透明度时,但我仍然获得默认的标题鼠标悬停效果。当用户将鼠标悬停在图像上时如何抑制这种效果?
我开始在c#中解析主题索引器,并在运行测试任务时遇到问题:
Index.cs:
class Index
{
double[] arr;
public int Length
{
get;
set;
}
public double this[int x]
{
get { return arr[x]; }
set
{
arr[x] = value;
}
}
public Index(double[] arr1, int x, int y)
{
Length = y;
arr = arr1;
for (int i = x; i <= y; i++)
{
if (i == 0)
{
arr[i] = arr1[i + 1];
}
else
{
arr[i - 1] = arr1[i];
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
Program.cs中
static void …Run Code Online (Sandbox Code Playgroud) 我的代码中有一个位置,我需要等待在传感器上识别任一个手指,或者用户按下一个键以中止此操作并返回主菜单.
我尝试使用条件变量Monitor和锁定概念之类的东西但是当我尝试提醒主线程时,没有任何反应.
码:
private static object _syncFinger = new object(); // used for syncing
private static bool AttemptIdentify()
{
// waiting for either the user cancels or a finger is inserted
lock (_syncFinger)
{
Thread tEscape = new Thread(new ThreadStart(HandleIdentifyEscape));
Thread tIdentify = new Thread(new ThreadStart(HandleIdentify));
tEscape.IsBackground = false;
tIdentify.IsBackground = false;
tEscape.Start();
tIdentify.Start();
Monitor.Wait(_syncFinger); // -> Wait part
}
// Checking the change in the locked object
if (_syncFinger is FingerData) // checking for identity found
{ …Run Code Online (Sandbox Code Playgroud) 我正在尝试拆分 SQL 查询脚本,并且在创建表上,我只想要最外面括号内的内容,而忽略内部的任何括号,这些括号主要描述列类型的最大字符数。
这是我的查询示例:
CREATE TABLE IF NOT EXISTS %SCHEMA%.business (
id UUID NOT NULL,
name VARCHAR(50) NOT NULL,
DBA VARCHAR(50),
isactive BOOL NOT NULL DEFAULT TRUE,
isdeleted BOOL NOT NULL DEFAULT FALSE,
createdon TIMESTAMP(6) WITHOUT TIME ZONE NOT NULL
)
WITH (OIDS = FALSE)
Run Code Online (Sandbox Code Playgroud)
我想取回描述列的所有内容。我已经尝试过这些
\(([^\)]*)\)
Run Code Online (Sandbox Code Playgroud)
在第一个 (50) 处停止,并读取另一个 (50) 和 (6),但不读取其他任何内容,并且不会到达外部括号的末尾。
\((\d+)\)
Run Code Online (Sandbox Code Playgroud)
这只会读取里面的括号,这稍后可能有用,但我只返回两个 (50) 和 (6)。
什么正则表达式可以捕获括号内的所有内容?即使它确实捕获了更多,我也可以稍后通过代码删除多余的字符串。
我一直在寻找一个新手问题,但找不到一个简单的例子。谁能给我一个简单的例子,如何将 MethodBody 放入最可用的字符串结果中?喜欢:
using Mono.Cecil;
using Mono.Cecil.Cil;
namespace my
{
public class Main
{
public Main()
{
// phseudo code, but doesnt work
Console.Write( getMethod("HelloWorld").GetMethodBody().ToString() );
}
public void HelloWorld(){
MessageBox.Show("Hiiiiiiiiii");
}
}
}
Run Code Online (Sandbox Code Playgroud) 我有一个包含双精度数的数组。现在我想从数组中获取 3 个最高值,并且我想知道它们的索引是什么。
这是我的代码:
var threeHighest = wineOfferCounter.OrderByDescending(x => x).Take(3).ToArray();
var firstIndex = wineOfferCounter.ToList().IndexOf(threeHighest[0]);
var secondIndex = wineOfferCounter.ToList().IndexOf(threeHighest[1]);
var thirdIndex = wineOfferCounter.ToList().IndexOf(threeHighest[2]);
Console.WriteLine("Offer " + firstIndex + " bought " + threeHighest[0] + " times");
Console.WriteLine("Offer " + secondIndex + " bought " + threeHighest[1] + " times");
Console.WriteLine("Offer " + thirdIndex + " bought " + threeHighest[2] + " times");
Run Code Online (Sandbox Code Playgroud)
但是当wineOfferCounter包含两个或多个相同的值时,我会得到第一个索引两次。相反,我想获得唯一的索引。因此,如果在位置处的wineOfferCounter[3]值是 25,并且在wineOfferCounter[6]处的值也是 25。结果是:
"Offer 3 bought 25 times"
"Offer 3 bought 25 times" …Run Code Online (Sandbox Code Playgroud) 我正在尝试绘制自己的工具提示。但我无法摆脱标准阴影。
它是一个标准的WinForm应用程序,有很多表单。因此是
Application.EnableVisualStyles();
Run Code Online (Sandbox Code Playgroud)
当应用程序启动时调用并需要。如果我注释掉这一行,它就会起作用。我在下面制作了一个最小的 WinForm 应用程序。如果EnableVisualStyles被注释掉,它只绘制一个红色矩形。当我取消注释时,它会绘制一个带有阴影的红色矩形。
有谁知道如何解决这个问题?如何拥有 Application.EnableVisualStyles(),并拥有 100% OwnerDrawn 的工具提示,而没有任何标准阴影?
最小的 WinForm 应用程序在这里:
using System;
using System.Drawing;
using System.Windows.Forms;
namespace ToolTipExample
{
public class MainForm : Form
{
[STAThread]
static void Main()
{
// Comment out below line and it works.
Application.EnableVisualStyles();
Application.Run(new MainForm());
}
private ToolTip toolTip;
private Button button;
public MainForm()
{
toolTip = new ToolTip();
toolTip.OwnerDraw = true;
toolTip.Draw += new DrawToolTipEventHandler(toolTip1_Draw);
toolTip.Popup += new PopupEventHandler(toolTip1_Popup);
button = new Button();
button.Location = new Point(25, 25);
button.Text …Run Code Online (Sandbox Code Playgroud) c# ×9
linq ×2
.net ×1
c#-7.2 ×1
codeigniter ×1
datatemplate ×1
deadlock ×1
fingerprint ×1
heap ×1
iqueryable ×1
mono.cecil ×1
mutex ×1
php ×1
reflection ×1
regex ×1
routing ×1
stack ×1
string ×1
tooltip ×1
winforms ×1
wpf ×1
xaml ×1