我正在使用PHP.我想从头开始创建一个MVC设置,以了解有关MVC如何工作的更多信息.我想使用带有斜杠的干净网址作为参数的分隔符.在GET方法表单中,人们如何做到这一点?或者人们一起避免GET方法形式?
截至目前,我可以想象的方式是:
任何建议或建议阅读欢迎.
我有一个包含输入元素的克隆div,所有这些都被禁用.我试图使用以下JQuery代码删除每个div的子项的禁用属性.
clonedElement.children().removeAttr('disabled');
Run Code Online (Sandbox Code Playgroud)
我没有大量的JQuery经验,所以我可能误解了它的工作方式.我应该如何从克隆节点的所有子节点中删除"disabled"属性?
如果有帮助,clonedElement是使用JQuery .clone()方法创建的.
用于测试的HTML ---
<div id="original_item" class="hidden">
<div class="row_submit">
<div class="med_field">
<p>Product:</p>
<select name="product[]">
<option></option>
</select>
</div>
<div class="small_field">
<p>Type:</p>
<select name="type[]">
<option></option>
</select>
</div>
<div class="small_field">
<p>Price:</p>
<input type="text" name="price[]" value="test" disabled="disabled" />
</div>
<div class="small_field">
<p>Quantity:</p>
<input type="text" name="quantity[]" />
</div>
<img onclick="removeItem(this);" title="Remove Item" style="margin: 18px 0 0 12px;" src="icons/cancel.gif" />
</div>
<input type="hidden" name="warehouse_data[]" />
</div>
Run Code Online (Sandbox Code Playgroud) 我有一个htaccess重写规则,如果请求的文件不存在则重写,但如果请求属于特定目录,我也希望此规则忽略此规则.但我不确定如何做到这一点.
我目前的重写规则是这样的:
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /index.php/$1 [L]
Run Code Online (Sandbox Code Playgroud)
如何修改忽略特定目录?
我正在创建一个MVC框架,该框架通过动作的方法参数将“动作”参数之后的所有url参数传递给请求的动作。
因此,如果网址是:
host/controller_name/action_name/param1/param2
Run Code Online (Sandbox Code Playgroud)
发生以下情况(当然是简化的):
$requested_controller = new controller_name();
call_user_func_array(array($requested_controller, action_name), array(param1, param2);
Run Code Online (Sandbox Code Playgroud)
问题出在错误报告中。如果请求的网址参数数量错误(动作需要两个参数,但网址仅包含一个参数,则会收到警告消息,然后造成严重破坏)。
由于这是程序错误而不是异常,因此我无法以任何方式尝试/捕获它,可以吗?有没有办法在尝试运行该操作方法之前检查它的预期参数数量?还是我应该以一种完全不同的方式来攻击它?
编辑(解决方案)
$action_method_relfection = new ReflectionMethod($requested_controller, $requested_action);
if (count($path_variables) < $action_method_relfection->getNumberOfRequiredParameters() || count($path_variables) > $action_method_relfection->getNumberOfParameters()) {
// if not, redirect to 404 error
self::redirect_to_404();
}
Run Code Online (Sandbox Code Playgroud) 我正在创建一个JavaScript类.一些方法包含使用JQuery的AJAX调用.我遇到的问题是this
由于范围的变化,我无法在AJAX回调中使用关键字.我想出了一个hackey解决方案,但我想知道最好的做法是什么?
这是一个例子:
var someClass = function() {
var someElement = $('form');
this.close = function() {
someElement.remove();
};
this.query = function() {
$.ajax({
url: someurl,
success: function() {
this.close(); // does not work because `this` is no longer the parent class
}
});
};
};
Run Code Online (Sandbox Code Playgroud) 查看具有类似标题的问题,但没有一个完全覆盖我的问题.我有一个看起来像这样的查询.
SELECT
bus_products.id
, bus_products.prod_name
, (
SELECT SUM(bus_warehouse_entries.quantity) * bus_products.weight
FROM bus_warehouse_entries
WHERE bus_warehouse_entries.org_product_code = bus_products.prod_code
AND bus_warehouse_entries.type = 0
AND bus_warehouse_entries.request_date >= 'some_date_here'
) AS reg_yr
FROM
bus_products
WHERE 1'some_search_params'
GROUP BY bus_products.prod_name
ORDER BY 'some_sort'
Run Code Online (Sandbox Code Playgroud)
当我按产品名称分组时,子查询通过匹配产品代码进行选择.多个产品代码可能具有相同的产品名称.如果存在多个具有相同名称的代码,则上述查询仅获取由于分组而产生的第一个代码的数量.
我想在子查询周围添加一个SUM(),以便获得具有该特定产品名称的所有产品代码的总和,但这会在子查询SELECT的开头导致语法错误.关于如何完成另一种方式的任何建议?
为简化起见,表格看起来像这样
bus_products
id | prod_code | prod_name | weight
bus_warehouse_entries
org_product_code | quantity | type | request_date
Run Code Online (Sandbox Code Playgroud) 我是否遗漏了什么或闭包根本不能作为类方法工作?以这个为例:
$foo = new stdClass();
$foo->bar = function() {
echo '@@@';
};
$foo->bar();
Run Code Online (Sandbox Code Playgroud)
似乎给了我一个错误“致命错误:在 X 行的 /blah/blah.php 中调用未定义的方法 stdClass::bar()”
这不应该调用放置在“bar”属性中的闭包吗?
因为undefined等于false,我想知道是否有任何退回来替换以下代码:
public static function user_access_level() {
if (isset($_SESSION['lev_user_access'])) {
return $_SESSION['lev_user_access'];
} else {
return false;
}
}
Run Code Online (Sandbox Code Playgroud)
有:
public static function user_access_level() {
return $_SESSION['lev_user_access'];
}
Run Code Online (Sandbox Code Playgroud) 这是错误
您的SQL语法有错误; 检查与MySQL服务器版本对应的手册,以便在第1行的"order ASC LIMIT 100"附近使用正确的语法.
这是传递给PDO的查询,用于准备好的执行
SELECT * FROM web_menu_items WHERE menuId = ? ORDER BY order ASC LIMIT 100
这是传递给准备好的执行的变量
array(0 => "1")
这是表结构
CREATE TABLE IF NOT EXISTS `web_menu_items` (
`id` int(11) NOT NULL auto_increment,
`menuId` int(11) NOT NULL,
`order` int(11) NOT NULL,
`requiredAccess` int(11) NOT NULL,
`hideIfNotAccess` int(11) NOT NULL,
`label` varchar(128) NOT NULL,
`link` varchar(128) NOT NULL,
`tagId` varchar(32) NOT NULL,
PRIMARY KEY (`id`),
KEY `menuId` (`menuId`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=5 ;
Run Code Online (Sandbox Code Playgroud)
我在这里看不到什么?为什么这是语法错误?
php ×6
javascript ×2
jquery ×2
mysql ×2
.htaccess ×1
closures ×1
forms ×1
methods ×1
mod-rewrite ×1
parameters ×1
rest ×1
url-routing ×1