首页 \ 问答 \ 超薄框架和雄辩的ORM(Slim Framework and Eloquent ORM)

超薄框架和雄辩的ORM(Slim Framework and Eloquent ORM)

我正在使用Slim FrameworkLaravel's Eloquent ORM ,这是我的代码:

user.php的

class User extends \Illuminate\Database\Eloquent\Model
{
    protected $table = 'accounts';
}

的index.php

require_once 'vendor/autoload.php';

// Models
include 'app/models/User.php';

$app = new \Slim\Slim();

// Database information
$settings = array(
    'driver' => 'mysql',
    'host' => '127.0.0.1',
    'database' => 'photo_mgmt',
    'username' => 'root',
    'password' => '',
    'collation' => 'utf8_general_ci',
    'prefix' => '',
    'charset'   => 'utf8',
);

$container = new Illuminate\Container\Container;
$connFactory = new \Illuminate\Database\Connectors\ConnectionFactory($container);
$conn = $connFactory->make($settings);
$resolver = new \Illuminate\Database\ConnectionResolver();
$resolver->addConnection('default', $conn);
$resolver->setDefaultConnection('default');
\Illuminate\Database\Eloquent\Model::setConnectionResolver($resolver);

$app->get('/', function () use ($app) {
    $users = \User::all();
    echo $users->toJson();
});

$app->run();

正如您在我的代码中看到的,我必须在index.php包含User.php文件。 但是,如果我有多个型号怎么办? 我可以只包含一个文件夹,所有模型也将被包含在内,这样它就不会显得凌乱,包括索引中的每个模型文件。

先谢谢你。

更新:我正在使用我看到的这段代码

foreach (glob("app/models/*.php") as $filename)
{
    include $filename;
}

有一个更清洁的方式吗?


I'm using Slim Framework together with Laravel's Eloquent ORM and this is my code:

User.php

class User extends \Illuminate\Database\Eloquent\Model
{
    protected $table = 'accounts';
}

index.php

require_once 'vendor/autoload.php';

// Models
include 'app/models/User.php';

$app = new \Slim\Slim();

// Database information
$settings = array(
    'driver' => 'mysql',
    'host' => '127.0.0.1',
    'database' => 'photo_mgmt',
    'username' => 'root',
    'password' => '',
    'collation' => 'utf8_general_ci',
    'prefix' => '',
    'charset'   => 'utf8',
);

$container = new Illuminate\Container\Container;
$connFactory = new \Illuminate\Database\Connectors\ConnectionFactory($container);
$conn = $connFactory->make($settings);
$resolver = new \Illuminate\Database\ConnectionResolver();
$resolver->addConnection('default', $conn);
$resolver->setDefaultConnection('default');
\Illuminate\Database\Eloquent\Model::setConnectionResolver($resolver);

$app->get('/', function () use ($app) {
    $users = \User::all();
    echo $users->toJson();
});

$app->run();

As you can see in my code, I have to include the User.php file in my index.php. But what if I have multiple models? Can I just include a folder and all models will also be included so that it won't look messy including every model file in my index.

Thank you in advance.

UPDATE: I'm using this piece of code I saw

foreach (glob("app/models/*.php") as $filename)
{
    include $filename;
}

Is there a cleaner looking way?


原文:https://stackoverflow.com/questions/33512676
更新时间:2022-09-05 06:09

最满意答案

如果您提供适当的DOCTYPE,IE8将以IE8标准模式呈现,如<!DOCTYPE html> 。 在这种情况下, <meta http-equiv="x-ua-compatible" content="IE=8">不需要强制它。

添加它的唯一结果是即将发布的IE9将在IE8兼容模式下呈现页面。 但是如果你真的真的想因为某种原因添加它,并且仍然将IE9保持在自己的标准模式中,你可以使用条件注释解决它

<!--[if IE 8]>
  <meta http-equiv="x-ua-compatible" content="IE=8">
<![endif]-->

我真的没有看到添加它的意义。 只需要<!DOCTYPE html>确保所有浏览器(甚至包括IE6)的标准模式。


IE8 will render in IE8 standards mode if you provide an appropriate DOCTYPE, like <!DOCTYPE html>. <meta http-equiv="x-ua-compatible" content="IE=8"> is unneeded to force it in this case.

The only consequence of adding it though would be that the soon to be released IE9 will render the page in IE8 compatibility mode. But if you really really wanted to add it for some reason, and still keep IE9 in its own standards mode you can work around it with a conditional comment

<!--[if IE 8]>
  <meta http-equiv="x-ua-compatible" content="IE=8">
<![endif]-->

I just really don't see a point to adding it though. Just have <!DOCTYPE html> that will ensure standards mode in ALL browsers (including even IE6).

相关问答

更多
  • 它适用于Google的Chrome Frame浏览器加载项。 ChromeFrame可以安装在各种版本的IE上(特别适用于不能很好地使用现代网络功能的旧版本)。 它实际上是在IE浏览器内部运行Chrome浏览器。 在元标记的情况下,IE应该以标准模式(大多数当前版本的“Edge”)运行 - 并激活铬框架(如果存在)。 我通常对IE的旧版本做一些有条件的浏览器,允许用户作为选项安装附加组件。 更多这里: chrome框架API (请注意,Google Chrome Frame不再受支持) It's for G ...
  • 该标签将尝试强制浏览器使用浏览器支持的最新呈现模式。 它不会触发兼容模式。 请注意,标签必须是头部中的第一个标签,否则将无法正常工作。 这个事实有利于使用HTTP头,如果可能,HTTP头中的顺序并不重要。 如果在使用标题或元标记时,如果浏览器静止图像处于兼容模式,则可能是以下原因之一: 你错过了一个理智的doctype 浏览器已设置为始终使用兼容性模式 该站点托管在“Intranet站点”上,并且设置了Intranet站点的默认设置 更改浏览器兼容性视图设置 Microsoft至少认为192.168.xx在 ...
  • X-UA兼容性不是“标准”HTML(FSVO“标准”,涉及出现在规范引用的公开编辑的维基页面上 ),或者验证器不是该维基的当前状态。 在撰写本文时(20130326),X-UA兼容版将出现在Wiki页面上,该部分指出:“以下建议的扩展不符合HTML规范中的所有注册要求,因此尚未被允许有效文档“。 所以验证器是正确的拒绝这个值。 Either X-UA-Compatible is not "standard" HTML (FSVO "standard" that involves appearing on a ...
  • 2015年10月更新 这个答案是在几年前发布的,现在问题确实应该是你应该考虑使用X-UA-Compatible标签在你的网站上,微软对其浏览器的更改(更多的是在下面)。 根据您支持的Microsoft浏览器,您可能不需要继续使用X-UA-Compatible标记。 如果您需要支持IE 9或IE 8,那么我建议使用该标签。 如果您只支持最新的浏览器(IE 11和/或Edge),那么我将考虑删除此标签。 附加信息如下: X-UA兼容的元标记允许网页作者选择页面应该呈现的Internet Explorer版本。 ...
  • 您的X-UA-Compatible http-equiv字符串无效。 它有2个值: IE = 8(IE 8标准渲染模式) IE =边缘(最新引擎) 但是,语法不正确。 正确的语法是: 指定多个值时,将使用最高值。 那是, 在IE9中,页面将以IE 9标准渲染模式呈现。 在IE8中,页面将以IE 8标准渲染模式呈现。 解决方案:修复语法并重试。 参考: https://develope ...
  • 试试看 this.meta.addTag({ name: 'http-equiv', content: 'IE=edge' }); Try that this.meta.addTag({ name: 'http-equiv', content: 'IE=edge' });
  • 从IE开发人员文档中, 定义文档兼容性 : ... X-UA-Compatible标头不区分大小写; 但是,它必须出现在除了title元素和其他元元素之外的所有其他元素之前的网页标题(HEAD部分)中。 ... 默认情况下,RichFaces 3.3.3自动包含元素,这些元素在原始模板内容之前的顶部引用特定于RichFaces的CSS样式表。 因此,HTML 元素的X-UA-Compatible标头总是无法在RichFaces 3.3.3 webapp中工作。 它在本地开 ...
  • 如果您提供适当的DOCTYPE,IE8将以IE8标准模式呈现,如 。 在这种情况下, 不需要强制它。 添加它的唯一结果是即将发布的IE9将在IE8兼容模式下呈现页面。 但是如果你真的真的想因为某种原因添加它,并且仍然将IE9保持在自己的标准模式中,你可以使用条件注释解决它