我有两个简单的表"items"和"orders".为简单起见,我们假设一个项目只能在一个订单中,或者一个订单只能包含一个项目.
现在,因为这可以使用简单的一对一关系实现,我可以执行以下操作:
我可以将orders表的主键添加到items表中,如下所示
//Table Items
item_id, item_name, order_id
1, shoes, 1
2, watch, 2
//Table Orders
order_id, customer
1, James
2, Rick
Run Code Online (Sandbox Code Playgroud)
或者我可以将items表的主键添加到orders表中,如下所示
//Table Items
item_id, item_name
1, shoes
2, watch
//Table Orders
order_id, customer, item_id
1, James, 1
2, Rick, 2
Run Code Online (Sandbox Code Playgroud)
哪一个是正确的,为什么?是否有任何指导线来决定哪个键在哪里?当然,常识会在上面的简单例子中起作用,但在复杂的例子中我们如何决定?
mysql database database-design entity-relationship one-to-one
我似乎无法理解战略模式提供的优势.请参阅下面的示例.
//Implementation without the strategy pattern
class Registry {
public function Func1(){
echo 'called function 1';
}
public function Func2(){
echo 'called function 2';
}
}
$client = new Registry();
$client->Func1();
$client->Func2();
//Implementation with strategy pattern
interface registry {
public function printMsg();
}
class Func1 implements registry {
public function printMsg(){
echo 'called function 1';
}
}
class Func2 implements registry {
public function printMsg(){
echo 'called function 2';
}
}
class context {
public function printMsg(Registry $class){
$class->printMsg();
} …Run Code Online (Sandbox Code Playgroud) 我有一个简单的JSON文件,如下所示:
{
"products": [
{
"title": "United Colors of Benetton Men's Shirt",
"description": "Cool, breezy and charming – this solid green shirt from United Colors of Benetton is born on the beach. Effortlessly classy, this full sleeved shirt is perfect when worn with faded blue jeans and a pair of shades for a weekend get-together.",
"quantity": "10",
"cost": "3.00",
"brand": "United",
"image": "catalog/images/img2.jpg",
"category": "1",
"popularity": "100"
}
]
}
Run Code Online (Sandbox Code Playgroud)
我使用Mustache.js将这个JSON文件显示在模板中:
<table class="product-list">
{{#products}}
<tr>
<td>
<table class="product">
<tr>
<td …Run Code Online (Sandbox Code Playgroud) *.ts我在使用 ts-node运行文件时遇到问题。
我的项目的目录结构如下所示。
-- project dir
-- src
-- services
-- module1
-- file1.ts (classA)
-- file2.ts (classB)
-- index.ts (contains export statements like export * from file1.ts)
-- application.ts
Run Code Online (Sandbox Code Playgroud)
这是我在tsconfig.json文件中配置的内容。
{
"compilerOptions": {
"lib": [
"es2020",
"dom"
],
"baseUrl": ".",
"paths": {
"@src/*": ["src/*"],
"@tests/*": ["tests/*"],
},
"module": "CommonJS",
"target": "es2020",
"strict": true,
"alwaysStrict": true,
"declaration": true,
"noImplicitAny": true,
"strictNullChecks": true,
"noImplicitThis": true,
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"resolveJsonModule": true,
"noImplicitReturns": true,
"inlineSourceMap": true,
"inlineSources": …Run Code Online (Sandbox Code Playgroud) 我似乎不明白接口如何实现松耦合的概念?您可能会发现这个问题与其他问题重复,但我已经阅读了许多与该主题相关的答案,但没有找到令人满意的解释。
下面是许多开发人员实现松散耦合的示例。
interface shape {
public function sayName();
}
class Circle implements shape {
public function sayName(){
echo 'Hello my name is circle';
}
}
class Square implements shape {
public function sayName(){
echo 'Hello my name is square';
}
}
class Creator {
public $shape = null;
public function __construct(Shape $shape){
$this->shape = $shape;
}
}
$circle = new Creator(new Circle());
$circle->sayName();
$square = new Creator(new Square());
$square->sayName();
Run Code Online (Sandbox Code Playgroud)
在上面的例子中我们使用接口的多态性来实现松耦合。但我不认为这段代码是松散耦合的。在上面的示例中,调用代码(客户端)使用“new”运算符直接引用“Circle”和“Square”类,因此创建了紧密耦合。
为了解决这个问题,我们可以这样做。
接口形状 { 公共函数 sayName(); }
class Circle implements shape …Run Code Online (Sandbox Code Playgroud) 我的应用程序有以下目录结构:
application
modules
default
controllers
models
views
Bootstrap.php
test
controllers
models
views
Bootstrap.php
Run Code Online (Sandbox Code Playgroud)
以下是模块特定引导程序文件的代码:
//default/bootstrap.php
class Default_Bootstrap extends Zend_Application_Module_Bootstrap
{
protected function _initMessageDefault(){
echo "called default module's bootstrap file";
}
}
//test/bootstrap.php
class Test_Bootstrap extends Zend_Application_Module_Bootstrap
{
protected function _initMessageTest(){
echo "called test module's bootstrap file";
}
}
Run Code Online (Sandbox Code Playgroud)
现在如果我调用默认控制器即www.domain.com/index,我可以看到以下输出:
called default module's bootstrap file
called test module's bootstrap file
Run Code Online (Sandbox Code Playgroud)
我的问题是为什么两个模块的bootstrap文件被调用?当我调用默认模块时,不应该只调用默认模块的boostrap文件吗?
这是一个错误还是我做错了什么?
感谢您的帮助.
我需要使用zend框架创建一个多维数组表单.当我发布表单时,我应该能够得到以下结果作为帖子.
Array
(
[Address] => Array
(
[customer] => Array
(
[name] => Customer Name
)
[guest] => Array
(
[name] => Guest Name
)
)
)
Run Code Online (Sandbox Code Playgroud)
由于某种原因,我无法得到上述结果.到目前为止,我得到的结果是这个.
Array
(
[customer_name] => Customer Name
[guest_name] => Guest Name
)
Run Code Online (Sandbox Code Playgroud)
所以我的问题是Zend_Form是否支持多维表格数组?如果有,怎么样?
提前致谢...
我正在开发一个从不同站点导入多个 CSV 文件的小应用程序。每个站点都有自己的日期格式。一些格式如下。
'2013-12-04 11:32:21 +0000'
'04/12/2014 +0000'
'04/12/2014 +0000 11:32:21'
'Fri Mar 14 18:19:26 +0000 2014'
Run Code Online (Sandbox Code Playgroud)
我需要将上述格式转换为简单的格式,如'd-m'Y'. 这里的问题是格式事先不知道,每次需要将新的 CSV 文件添加到系统时,我都无法更改代码。
有没有一种方法可以将所有这些格式转换为简单格式?我在下面尝试过,但它不起作用,我找不到任何其他解决方案。
$date = DateTime::createFromFormat(strtotime('2013-12-04 11:32:21 +0000'), '2013-12-04 11:32:21 +0000');
print_r($date->format('d-m-Y')); //Doesn't work
Run Code Online (Sandbox Code Playgroud)
在此先感谢您的帮助。
由于某种原因,产品类别页面中缺少分页.它适用于所有其他页面,只是在产品类别页面上丢失.
我已经在商店页面上扩展了分页模板及其调用,但出于某种原因没有在类别页面上调用.
任何人都能说明为什么会这样吗?
此外,我在这个页面上有大约32个产品,应该足以打破页面上的记录.
提前致谢.
用户必须键入维度(它是一个四边形矩阵),并生成随机字母.例如:generateMatrix 3
[('a', 'f', 'j'), ('t', 'a', 'b'), ('c', 'y', 'k')]
Run Code Online (Sandbox Code Playgroud)
每个元组都是一条线
php ×5
oop ×2
architecture ×1
database ×1
datetime ×1
haskell ×1
javascript ×1
json ×1
mustache ×1
mysql ×1
node-modules ×1
node.js ×1
one-to-one ×1
ts-node ×1
typescript ×1
woocommerce ×1
wordpress ×1
zend-form ×1