我有以下代码在第一次使用时有效:
$("#CompDD").change(function () {
//var parts = (window.location.pathname.split("/"));
var ctrlName = '@ViewContext.RouteData.Values["Controller"].ToString()';
var actnName = '@ViewContext.RouteData.Values["Action"].ToString()';
var url = (ctrlName + "/" + actnName + "/?SearchString=" + $('#CompDD option:selected').text() + "&atton=" + $('#AttDD option:selected').val());
//delete ctrlName;
// delete actnName;
//window.location = ($(location).attr('href') + "/?SearchString=" + $('#CompDD option:selected').text() + "&atton=" + $('#AttDD option:selected').val());
//window.location = (ctrlName + "/" + actnName + "/?SearchString=" + $('#CompDD option:selected').text() + "&atton=" + $('#AttDD option:selected').val());
//$(location).attr('href', url);
window.location.href = url;
//alert(ctrlName + "\n" + actnName);
}); …Run Code Online (Sandbox Code Playgroud) 当我尝试渲染一个基本上在幻灯片中显示一些幻灯片的局部视图时,我遇到了一些错误.
幻灯片存储在数据库中,我从调试中知道我的控制器方法肯定会得到一个幻灯片对象数组.
但它仍然抛出这个错误,我不知道为什么.我得到的错误是:
{"执行处理程序'System.Web.Mvc.HttpHandlerUtil + ServerExecuteHttpHandlerAsyncWrapper'."}的子请求时出错,内部异常为:
HttpServerUtility.Execute在等待异步操作完成时被阻塞.
我假设它与同步有关,但我不确定是什么.
任何帮助将不胜感激.
父视图(索引)
@{
ViewBag.Title = "Title";
Layout = "~/Views/Shared/_Layout.cshtml";
ViewBag.IsIndex = true;
}
<!-- BEGIN .featured-slider -->
<div class="featured-slider">
<!-- BEGIN .slider-background -->
<div class="slider-background">
<!-- BEGIN .row -->
<div class="row">
<!-- BEGIN .sixteen columns -->
<div class="sixteen columns">
@{
Html.RenderAction("Slideshow", new { controller = "home" });
}
<!-- END .sixteen columns -->
</div>
<!-- END .row -->
</div>
<!-- END .slider-background -->
</div>
<!-- END .featured-slider -->
</div>
Run Code Online (Sandbox Code Playgroud)
控制器方法:
public async …Run Code Online (Sandbox Code Playgroud) 我想使用MVC模式将我的逻辑从演示文稿和数据中划分出来。
好吧,我一直在寻找我。但事实是,我什至不知道要搜索什么。
我正在尝试在php中设置MVC框架。我正在关注youtube上的教程,并且停留在路由点。
我已经阅读了很多指南,每个指南都以不同的方式讲课,只会造成更多的混乱。
关键是这样的:
我有一个.htaccess文件,其中包含一些指令(但是问题是我不知道所有这些指令的含义。我从未理解过htaccess逻辑)
Options -MultiViews
RewriteEngine On
#I think this sets the base url of the site?
RewriteBase /~caiuscitiriga/mvc/public
#What does this mean??
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
#AND THIS?!
RewriteRule ^(.+)$ index.php?url=$1 [QSA,L]
Run Code Online (Sandbox Code Playgroud)
然后我有这些php脚本:
<?php
require_once '../app/init.php';
$app = new App();
Run Code Online (Sandbox Code Playgroud)
<?php
require_once 'core/App.php';
require_once 'core/Controller.php';
Run Code Online (Sandbox Code Playgroud)
不要问我为什么使用filter_var和rtrim。因为这正是我要弄清楚的。如我之前所说,此代码不是我的。我敢肯定,把戏完全在.htacess和App.php中,但我不明白其逻辑
class App{
protected $controller = 'home';
protected $method = 'index';
protected $params = [];
public function __construct()
{
print_r($this->parseUrl());
}
public …Run Code Online (Sandbox Code Playgroud) 在我看来,
@using(Html.BeginForm("Action", "Controller", FormMethod.Post)){
<div>
@Html.TextBox("text_1", " ")
@Html.TextBox("text_2", " ")
@if(Session["UserRole"].ToString() == "Manager"){
@Html.TextBox("anotherText_3", " ")
}
</div>
<button type="submit">Submit</button>
}
Run Code Online (Sandbox Code Playgroud)
在我的控制器中,
public ActionResult Action(FormCollection form){
if(!form.AllKeys.Contains("anotherText")){
ModelState.AddModelError("Error", "AnotherText is missing!");
}
}
Run Code Online (Sandbox Code Playgroud)
我有一个表单并发布到我的方法中,在我的方法中,我想检查 id 是否包含“anotherText”的文本框,但我使用 .Contains() 它总是给出 false,这在我的表单集合中找不到...如何我可以检查包含“anotherText”的 id 文本框是否存在吗?
我的模型中有一个查询,我需要在视图中打印数据
模型
function get_bank()
{
$query = $this->db->query("SELECT
(
12* (YEAR('account_add_date') - YEAR('start_date')) +
(MONTH('account_add_date') - MONTH('start_date'))
) AS differenceInMonth
->FROM ('bank')
WHERE mem_id = '".$this->session->userdata('id')."'");
return $query->result();
$data['account_age'] = $query->row_array();
}
Run Code Online (Sandbox Code Playgroud)
我试图在我的模型中打印输出,但它不起作用,我不知道我哪里出错了.我是MVC的新手并且仍然习惯它.
视图
<h2>age of account</h2>
<?php
$age = $this->model('profiles_model' , $data );
print "<h2>$age</h2>";
?>
Run Code Online (Sandbox Code Playgroud)
调节器
function index()
{
$data = array();
$this->load->model('user_profile/profiles_model');
$query = $this->profiles_model->get_bank();
if(!empty($query))
{
$data['records'] = $query;
}
$this->load->view('profile_view', $data);
}
Run Code Online (Sandbox Code Playgroud) 这是一个关于带有ajax调用的php mvc模式的奇怪问题.目的是制作更好,更动态的网络应用程序.我来解释一下:
当我学习php时,我特意使用了这种模式:
model.php
<?php
class myClass {
private $attrOne;
private $attrTwo;
public function getAttrOne() {
return $this->attrOne;
}
public function setAttrOne($attrOne) {
$this->attrOne = $attrOne;
}
public function getAttrTwo() {
return $this->attrTwo;
}
public function setAttrTwo($attrTwo) {
$this->attrTwo = $attrTwo;
}
// ----------------------------------------------------
public function doSelect() {
//some code
}
public function doInsert() {
//some code
}
public function doUpdate() {
//some code
}
public function doDelete() {
//some code
}
}
Run Code Online (Sandbox Code Playgroud)
Controller.php这样
<?php
require "../models/model.php";
if(isset($_POST['action'])) {
$action …Run Code Online (Sandbox Code Playgroud) 我对 codeigniter 非常陌生。我有一个 codeigniter 项目,我需要做一些更改。我已将其粘贴到 htdocs 并将 application/config/config.php 的 base_url 更改为 localhost 的路径。
并更改了 application/config/database.php 中的数据库连接
进行上述更改后,我的索引页在 localhost 上打开良好。但索引页中的所有链接都重定向到http://localhost/dashboard/ 。
我没有更改 .htaccess 文件内容。这里是 :
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
Run Code Online (Sandbox Code Playgroud)
如何解决这个问题?
我刚刚找到了这个代码,我不知道如何用谷歌搜索它。:-)
最后一个特质有什么作用? 我无法理解它的语法。如果花括号之间的那些行是新实例的参数,它不应该在括号之间吗?
<?php
namespace Laravel\Dusk;
use Closure;
use BadMethodCallException;
use Illuminate\Support\Str;
use Illuminate\Support\Traits\Macroable;
use Facebook\WebDriver\WebDriverDimension;
class Browser
{
use Concerns\InteractsWithAuthentication,
Concerns\InteractsWithCookies,
Concerns\InteractsWithElements,
Concerns\InteractsWithJavascript,
Concerns\InteractsWithMouse,
Concerns\MakesAssertions,
Concerns\WaitsForElements,
Macroable {
__call as macroCall;
}
// ...
}
Run Code Online (Sandbox Code Playgroud)
代码来自Laravel\Dusk。这是原始的GitHub 存储库和类本身
我在 laravel 项目中制作了一个更新表单来更新我数据库中的一些条目,但是当我按下提交按钮时,什么也没有发生。我不知道为什么。尝试了一切。这是表格:
<form action="{{ route('loans.update', $loan->id)}}" method="patch">
<p class="al-left">
{{csrf_field()}}
<label for="date">Date:</label>
<input type="date" name="date" value="{{$loan->data}}" id="date">
</p>
<p class="al-left">
<label for="name">Name:</label>
<input type="text" name="name" value="{{$loan->nume}}" id="name">
</p>
<p class="al-left">
<label for="period">Period(months):</label>
<input type="number" name="period" value="{{$loan->durata}}" id="period">
</p>
<p class="al-left">
<label for="month">Month Rate(euro):</label>
<input type="number" name="month" value="{{$loan->valoare_rata_luna}}" id="month">
</p>
<p class="al-left">
<label for="amount">Amount:</label>
<input type="number" name="amount" value="{{$loan->valoare_totala}}" id="amount">
</p>
<input type="submit" class="btn btn-sm btn-primary" name="submit" value="Edit">
<br>
<br>
</form>
Run Code Online (Sandbox Code Playgroud)
这是控制器中的删除功能:
public function update(Request $request, $id){
$id = Auth::id();
$loan …Run Code Online (Sandbox Code Playgroud) 我正在使用PHP 7.1.11
考虑以下代码:
<?php
class SimpleClass {
// property declaration
public $var = 'a default value';
// method declaration
public function displayVar() {
echo $this->var;
}
}
$instance = new SimpleClass();
$assigned = $instance;
$reference =& $instance;
$instance->var = '$assigned will have this value';
$instance = null; // $instance and $reference become null
var_dump($instance);
var_dump($reference);
var_dump($assigned);
?>
Run Code Online (Sandbox Code Playgroud)
以上程序的输出如下:
NULL
NULL
object(SimpleClass)#1 (1) {
["var"]=>
string(30) "$assigned will have this value"
}
Run Code Online (Sandbox Code Playgroud)
如果查看代码行,$reference =& $instance;您会注意到& instance创建了对现有类对象()的引用并将其分配给变量 …
php ×7
asp.net-mvc ×3
.htaccess ×2
c# ×2
codeigniter ×2
jquery ×2
ajax ×1
apache ×1
apache2 ×1
class ×1
database ×1
javascript ×1
laravel ×1
mysql ×1
object ×1
razor ×1
reference ×1
traits ×1
validation ×1