Kohana Start Configuration
Step 1:
.htaccess
# This is a sample .htaccess file. Simply replace
# RewriteBase below with the url path to this directory.
#
# Example:
# /shop/ - if an Apache alias points to ".../public/" (this folder)
# / - if this directory is reachable at the web root
#
# Server-Side includes
#
Options All
AddHandler server-parsed .scss
AddType text/css .scss
# enable rewrite engine
RewriteEngine On
SetEnv APP_ENVIRONMENT DEVELOPMENT
SetEnv APP_BASE_URL {your domain}
SetEnv APP_COUNTRY CN
#SetEnv WEB_PROXY XXXXXX
#SetEnv WEB_PROXY_PORT 8080
#SetEnv WEB_PROXY_USERPWD name:pass
# tell Apache for which URL rewrites should occur
# (the rules below are relative to this url)
RewriteBase /
# rewrite all requests which don't point to a file
# or an directory to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1
# turn off magic quotes in PHP
# (http://www.php.net/manual/en/security.magicquotes.whynot.php)
php_flag magic_quotes_gpc off
php_flag magic_quotes_runtime off
Step 2:
open the module in bootstrap.php file
Kohana::modules(array(
// 'auth' => MODPATH.'auth', // Basic authentication
'cache' => MODPATH.'cache', // Caching with multiple backends
// 'codebench' => MODPATH.'codebench', // Benchmarking tool
'database' => MODPATH.'database', // Database access
// 'image' => MODPATH.'image', // Image manipulation
'orm' => MODPATH.'orm', // Object Relationship Mapping
// 'unittest' => MODPATH.'unittest', // Unit testing
'userguide' => MODPATH.'userguide', // User guide and API documentation
));
Step 3:
Need to configure the bootstrap.php
Load some configuration outside
Log Configuration:
if(Kohana::$environment === Kohana::PRODUCTION) {
// we use syslog in production
Kohana::$log->attach(new Kohana_Log_Syslog("patrick"), array(Log::ERROR, Log::INFO));
define('_INFO', false);
define('_DEBUG', false);
} else {
/**
* Attach the file write to logging. Multiple writers are supported.
*/
Kohana::$log->attach(new Kohana_Log_File(APPPATH.'logs/default/info_log'), array(Log::INFO));
Kohana::$log->attach(new Kohana_Log_File(APPPATH.'logs/default/debug_log'), array(Log::DEBUG));
Kohana::$log->attach(new Kohana_Log_File(APPPATH.'logs/default/error_log'), array(Log::ERROR));
define('_INFO', true);
define('_DEBUG', true);
}
Language Configuration:
$supported_languages = Kohana::$config->load('project.language');
$request_lang = $_REQUEST['lang'];
if ($request_lang !== NULL && $supported_languages[$request_lang])
{
// attempt to change the language
Session::instance()->set('current_lang', $supported_languages[$request_lang]);
}
else
{
$current_lang = Session::instance()->get('current_lang');
if(empty( $current_lang ) || !in_array($current_lang, $supported_languages))
{
// zh_CN by default
$current_lang = 'zh_CN';
Session::instance()->set('current_lang', $current_lang);
}
}
$current_country = Session::instance()->get('current_country');
if(empty( $current_country )){
// fixed at CN
Session::instance()->set('current_country', 'CN');
}
Cache configuration:
try {
if(Kohana::$config->load('project.caching')){
$memcache = Cache::instance('memcache');
}
define('_MEMCACHE', Kohana::$config->load('project.caching'));
} catch (Exception $e) {
define('_MEMCACHE', false);
Kohana::$log->add(Log::ERROR,'Fehler beim Memcache initialisieren');
}
Step 4:
Copy /modules/database/config/database.php to /application/config/database.php
'connection' => array(
/**
* The following options are available for MySQL:
*
* string hostname server hostname, or socket
* string database database name
* string username database username
* string password database password
* boolean persistent use persistent connections?
*
* Ports and sockets may be appended to the hostname.
*/
'hostname' => 'localhost',
'database' => 'patrick',
'username' => 'root',
'password' => 'pass',
'persistent' => FALSE,
)
Then you can connect database and operate data.
Kohana View File
Way 1:
$this->response->body(View::factory('site'));
Site means the view file of site.php
Way 2:
$arr = array('xx'=>'12345');
$this->response->body(View::factory('site', $arr));
site.php view code:
<?php echo $xx; ?>
How to use the mysql through kohana
Read data:
Way 1:
$all_kohanas = ORM::factory('user')->where('credit', '>', 20)->find_all();
$result = ORM::factory('user')
->where('id', '=', '1000001')
->find();
$r = $result->as_array();
var_dump($r);
OR
echo $result->id;
Way 2:
$result = Db::select('id', 'username')
->from('user')
->where('id', '=', '1000002')
->execute();
$r = $result->as_array();
var_dump($r);
Insert Data:
Way 1:
$values = array('username' => 'patrick2', 'password' => 'patrick');
$id = Db::insert('user')->values($values)->execute('alternate');
Way 2:
$values = array('username' => 'patrick3', 'password' => 'patrick');
ORM::factory('user')->values($values)->save();
Update data:
$values = array('username' => 'patrick3', 'password' => 'patrickwu');
ORM::factory('user', 1)->values($values)->save();
Update the selected items:
ORM::factory('user', 'patrick')->set('password', md5('xxx'))->save();
Delete data:
Way 1:
ORM::factory('user', 1)->delete();
Way 2:
ORM::factory('user')->where('id', '=', '1')->find()->delete();
- 浏览: 325852 次
- 性别:
- 来自: 上海
最新评论
-
bu123dian:
都没有中文了么?英文看起来真的比较费劲
JIRA Git Plugin -
haohappy2:
We can call it dynamic content ...
Varnish and Nginx -
spidersea:
文中提到“利用 Varnish cache 减少了90%的数据 ...
Varnish and Nginx
相关推荐
功能说明: 系统主要包括首页,个人中心,医护人员管理,操作员管理,体温数据管理,隔离治疗管理,轮班调度管理,支援信息管理等功能模块。 环境说明: 开发语言:python Python版本:3.6.8 数据库:mysql 5.7数据库工具:Navicat11开发软件:pycharm
基于springboot的学院教学工作量统计系统源码数据库文档.zip
SciPy-1.11.1-cp311-cp311-linux_armv7l.whl
解压之后在elasticsearch的jdk\conf\security\java.policy文件下新增这段,然后重启es就可以使用了 permission java.net.SocketPermission "*", "connect,resolve"; permission java.lang.RuntimePermission "setContextClassLoader"; permission java.lang.RuntimePermission "accessDeclaredMembers"; permission java.lang.RuntimePermission "createClassLoader"; permission java.security.SecurityPermission "putProviderProperty.MySQLScramSha1Sasl"; permission java.security.SecurityPermission "insertProvider";
scipy-1.7.0-cp37-cp37m-linux_armv7l.whl
基于springboot的流浪动物管理系统源码数据库文档.zip
bimdata_api_client-4.0.2-py3-none-any.whl
206847144042651【第3版】第1章-信息化发展.pdf
文件快速搜索 Everything。包含安装包及语言包
环境说明: 开发软件:VS 2017 (版本2017以上即可,不能低于2017) 数据库:SqlServer2008r2(数据库版本无限制,都可以导入) 开发模式:mvc
科兴中维医药现代物流中心方案1(拆零货架+地推).dwg
基于springboot高校大学生竞赛项目管理系统源码数据库文档.zip
matplotlib-3.8.1-cp311-cp311-linux_armv7l.whl
2023-04-06-项目笔记-第三百二十一阶段-课前小分享_小分享1.坚持提交gitee 小分享2.作业中提交代码 小分享3.写代码注意代码风格 4.3.1变量的使用 4.4变量的作用域与生命周期 4.4.1局部变量的作用域 4.4.2全局变量的作用域 4.4.2.1全局变量的作用域_1 4.4.2.319局变量的作用域_319- 2024-11-18
方便大家学习扫雷游戏,设计扫雷游戏的实现,涉及多方面的知识
ta_lib-0.5.1-cp39-cp39-win_amd64.whl
matplotlib-3.5.0-cp39-cp39-linux_armv7l.whl
论文描述:该论文研究了某一特定领域的问题,并提出了新的解决方案。论文首先对问题进行了详细的分析和理解,并对已有的研究成果进行了综述。然后,论文提出了一种全新的解决方案,包括算法、模型或方法。在整个研究过程中,论文使用了合适的实验设计和数据集,并进行了充分的实验验证。最后,论文对解决方案的性能进行了全面的评估和分析,并提出了进一步的研究方向。 源码内容描述:该源码实现了论文中提出的新的解决方案。源码中包含了算法、模型或方法的具体实现代码,以及相关的数据预处理、实验设计和性能评估代码。源码中还包括了合适的注释和文档,以方便其他研究者理解和使用。源码的实现应该具有可读性、可维护性和高效性,并能够复现论文中的实验结果。此外,源码还应该尽可能具有通用性,以便在其他类似问题上进行进一步的应用和扩展。
matplotlib-3.8.2-cp39-cp39-linux_armv7l.whl
java源码资源配置ODBC数据源java源码资源配置ODBC数据源提取方式是百度网盘分享地址