- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
这是我在根目录中的索引文件的代码:
<?php
require 'vendor/autoload.php';
date_default_timezone_set('Asia/Seoul');
//$log = new Monolog\Logger('name');
//$log->pushHandler(new Monolog\Handler\StreamHandler('app.txt', Monolog\Logger::WARNING));
//$log->addWarning('Oh Noes.');
$app = new \Slim\Slim( array(
'view' => new \Slim\Views\Twig()
));
$app->add(new \Slim\Middleware\SessionCookie());
$view = $app->view();
$view->parserOptions = array(
'debug' => true
);
$view->parserExtensions = array(
new \Slim\Views\TwigExtension(),
);
//Path To Our View
$app->view->setTemplatesDirectory("app/view");
// Configs for mode "production"
$app->configureMode('production', function () use ($app) {
// Set the configs for production environment
$app->config(array(
'debug' => false,
'database' => array(
'db_host' => 'localhost',
'db_port' => '',
'db_name' => 'mini',
'db_user' => 'root',
'db_pass' => 'yaounde'
)
));
});
/******************************************** THE MODEL ********************************************************/
// Initialize the model, pass the database configs. $model can now perform all methods from Mini\model\model.php
$model = new \app\Model\Model($app->config('database'));
/************************************ THE ROUTES / CONTROLLERS *************************************************/
$app->get('/', function() use($app){
$app->render('about.twig');
})->name('home');
$app->get('/contact', function() use($app){
$app->render('contact.twig');
})->name('contact');
$app->post('/contact', function() use($app){
$name = $app->request->post('name');
$email = $app->request->post('email');
$msg = $app->request->post('msg');
if(!empty($name) && !empty($email) && !empty($msg)) {
$cleanName = filter_var($name, FILTER_SANITIZE_STRING);
$cleanEmail = filter_var($email, FILTER_SANITIZE_EMAIL);
$cleanMsg = filter_var($msg, FILTER_SANITIZE_STRING);
} else {
$app->flash('fail', 'All Fields Are Required.');
$app->redirect('contact');
}
$transport = Swift_MailTransport::newInstance();
$mailer = \Swift_Mailer::newInstance($transport);
$message = \Swift_Message::newInstance();
$message->setSubject('Simple Blog Contact Form Submission');
$message->setFrom(array(
$cleanEmail => $cleanName
));
$message->setTo(array('admin@localhost'));
$message->setBody($cleanMsg);
$result = $mailer->send($message);
if($result > 0) {
$app->flash('success', 'Thanks So Much! You are AWESOME!!!');
$app->redirect('contact');
} else {
$app->flash('fail', 'So Sorry, Something Went Wrong. Please Try Again!');
// log that there was an error
$app->redirect('/contact');
}
});
$app->run();
然后,我将 Model.php
放在文件夹 app\Model\Model.php
<?php
namespace app\Model;
use PDO;
class Model
{
function __construct($config)
{
}
}
我收到这个错误:
Fatal error: Class 'app\Model\Model' not found in E:\xampp\htdocs\aaaaaslim\index.php on line 43
最佳答案
您可以使用 Composer
加载您自己的命名空间。
只需将以下内容添加到您的 composer.json
。
"autoload": {
"psr-4": {
"app\\": "app/"
}
}
当您执行 composer update 时,自动加载将知道您的命名空间 app
并即时包含您的类,而无需手动导入它们。
关于php - 找不到 Slim 类。我不确定这里做错了什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32086566/
.net 4.0 添加了几个与线程相关的新类:ManualResetEventSlim , SemaphoreSlim和 ReaderWriterLockSlim . Slim 版本和旧类之间有什么区
一个新的 Slim 问题 我期待以下 Slim 模板 div class="header" h2 slim head p a test example of span Slim span a
我们正在考虑使用 Slim 3 作为我们 API 的框架。我已经搜索过 SO 和 Slim 文档,但找不到问题的答案。如果我们有不同的路由文件(例如 v1、v2 等)并且如果两个路由具有相同的签名,则
我正在尝试在 Slim-lang 的列表项中嵌套第二个 ul,如下所示: div.row ul.dropdown li Dropdown Option 1
我有以下代码导致 Slim::Parser::SyntaxError : p code.inline /charge 我希望这会输出 /charge但这只会让斯林姆不高兴。 为什么? 最佳答案 使
我想在子目录中使用 Slim 3,但似乎无法加载它。所有文件都包含在子目录中,包括 composer.json。这是我的 composer.json: "require": { "slim/s
我的 Slim 项目组织如下: - app -- Acme --- Auth ---- Auth.php (handles authentication) -- config --- developm
我在我的 svelte-typescript 项目上使用 clickOutside 指令,当我将自定义事件分配给相关元素时出现此错误 Type '{ class: string; onclick_ou
我们缩小了在 Silex 和 Slim PHP 框架之间的搜索范围,以便在我们的 Apache/PHP/MySQL 服务器上路由我们的 REST API。 两者似乎都有很好的评价。 Silex 可能有
我有一个 get表格中的路线 $app->get('/redirect[/{subject}]', function ($request, $response, $args) { }); 如果我向 /
任何人都可以解释在选择使用钩子(Hook)而不是使用中间件来实现身份验证或缓存等功能时是否有任何显着的优点或缺点? 例如 - 我可以通过自定义中间件获取请求对象并设置应用程序语言变量来实现翻译功能,该
在 Slim 3 中是否有类似 Laravel 的 back() helper 来获取之前的路由名称或 uri? 它不必特定于 Slim,我只是想重定向回上一页。 谢谢:) 最佳答案 假设你想要 re
在 Slim 3 中是否有类似 Laravel 的 back() helper 来获取之前的路由名称或 uri? 它不必特定于 Slim,我只是想重定向回上一页。 谢谢:) 最佳答案 假设你想要 re
我正在学习这里的教程: https://www.simplifiedcoding.net/php-restful-api-framework-slim-tutorial-1/ 导师说下载slim在:
如何从不同的 php 页面中的另一个函数调用 slim 函数 这里是 My.php: $app->get('/list/:id',function($id) { //fill array her
很抱歉提出这样一个愚蠢的问题,但在文档中找不到它: filename.slim filename.html.slim 这似乎是一种非常适合使用的语言。我以前使用过 HAML,所以我认为这将是一个相当不
请原谅我的无知,但我只是使用 npm 安装了 jQuery,并且在 jQuery 文件之间有一个名为 jquery.slim.js 的文件,slim 是什么?我知道 min 代表缩小但 slim 对我
TailwindCSS 看起来像是一个很棒的前端工具,但我想知道如何将它与 Rails Slim 模板语言一起使用? 例如: 如果我通过 HTML2SLIM 运行它,我会得到这个建议: .bg-re
TailwindCSS 看起来像是一个很棒的前端工具,但我想知道如何将它与 Rails Slim 模板语言一起使用? 例如: 如果我通过 HTML2SLIM 运行它,我会得到这个建议: .bg-re
我想将纤薄的 textmate 包安装到 sublime2。 我去了这个链接 slim textmate bundle 我将它克隆到 pristinepackage(根据 nettuts 网站),但什
我是一名优秀的程序员,十分优秀!