首页 \ 问答 \ CodeIgniter从href中删除index.php(CodeIgniter remove index.php from href)

CodeIgniter从href中删除index.php(CodeIgniter remove index.php from href)

在CodeIgniter应用程序中

这个链接有效

<a href="index.php/controller">link</a>

而这一个没有

<a href="controller">link</a>

配置有什么问题? 什么必须改变顺序链接工作开始时没有“index.php /”?

这没有成功:

1)添加到application / routes.php

$route['(:any)'] = 'controller';

2)添加到application / .htaccess

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

<Files "index.php">
AcceptPathInfo On
</Files>

3)在etc / apache2 / httpd.conf中取消注释

LoadModule rewrite_module libexec/apache2/mod_rewrite.so
LoadModule php5_module libexec/apache2/libphp5.so

In a CodeIgniter App

this link works

<a href="index.php/controller">link</a>

while this one doesn't

<a href="controller">link</a>

What's wrong with configuration? What has to be changed in order links work without "index.php/" at the beginning?

This is done without success:

1) added to application/routes.php

$route['(:any)'] = 'controller';

2) added to application/.htaccess

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

<Files "index.php">
AcceptPathInfo On
</Files>

3) uncommented in etc/apache2/httpd.conf

LoadModule rewrite_module libexec/apache2/mod_rewrite.so
LoadModule php5_module libexec/apache2/libphp5.so

原文:https://stackoverflow.com/questions/31941569
更新时间:2022-02-23 20:02

最满意答案

主要的问题是你不能有多个连接到只存在于内存中的SQLite数据库,因为每个连接都会创建一个新的空数据库。 请参阅SQLAlchemy文档 。 简而言之,您需要像这样创建引擎,以确保只有一个可以跨线程共享的实例。

from sqlalchemy.pool import StaticPool
engine = create_engine('sqlite://:memory:',
    connect_args={'check_same_thread': False},
    poolclass=StaticPool, echo=True)

一旦你这样做了,你就不需要scoped_session ,因为scoped_session是为每个线程创建一个连接,而你在这里不能这么做。

此外,请注意,如果您希望它正常工作(使用非SQLite引擎),则应该只有一个scoped_session实例。 你应该把它当作全局变量,然后它将能够处理线程本地的东西。


The main problem is that you can't have multiple connections to a SQLite database that only exists in memory, because each connection will create a new empty database. See the SQLAlchemy docs on this. In short, you need to create the engine like this to make sure that is only one instance that can be shared across threads.

from sqlalchemy.pool import StaticPool
engine = create_engine('sqlite://:memory:',
    connect_args={'check_same_thread': False},
    poolclass=StaticPool, echo=True)

Once you do that, you don't need scoped_session, because the point of scoped_session is to create one connection per each thread and you specifically can't do that here.

Also, note that you should have only one scoped_session instance if you want it to work correctly (with a non-SQLite engine). You should treat it as global variable and then it will be able to handle the thread-local stuff.

相关问答

更多
  • 这有点令人困惑,但是和scoped_session的显式类定义scoped_session , 下面还有一些代码,它从Session获取所有公共方法,并将它们设置为scoped_session代理。 query方法是这些公共方法之一。 It's a bit confusing, but as well as the explicit class definition of scoped_session, there is also code below that which takes all the pu ...
  • 您需要激活pyramid_tm补间。 [app:main] pyramid.includes = pyramid_tm 补间在每个请求之后提交事务,在新请求进入时隐式启动新事务。 当您不启动新事务时, 旧事务将不会看到在其他事务(线程)中提交的数据; 这是数据库事务的固有特性,因为不这样做会导致不一致错误。 You need to activate the pyramid_tm tween. [app:main] pyramid.includes = pyramid_tm The t ...
  • 好的 - 我没有回答所提出的问题,但我似乎确实有一个解决方法。 该问题似乎与scoped_session对象的代理行为有关。 据我所知, scoped_session()方法接受一个sessionmaker对象并使用它来创建线程本地session对象。 但是, scoped_session()方法不会返回此线程本地session 。 相反,它返回一个scoped_session对象,以某种方式(我不完全清楚)容纳线程本地session 。 要直接访问此线程本地会话,您可以执行scoped_session.r ...
  • 简短的回答 在Session上调用.remove() ,而不是session 。 答案很长 : scoped_session并不真正返回Session类。 相反,它创建了一个对象,它关注它所调用的线程。调用它将返回与该线程关联的现有Session实例或关联新线程并返回该线程。 线程本地是将线程与会话相关联的。 scoped_session对象上的remove方法删除当前与调用它的线程关联的会话对象。 这意味着它与scoped_session.__call__相反,这是一种令人困惑的API。 这是一个简短的P ...
  • 主要的问题是你不能有多个连接到只存在于内存中的SQLite数据库,因为每个连接都会创建一个新的空数据库。 请参阅SQLAlchemy文档 。 简而言之,您需要像这样创建引擎,以确保只有一个可以跨线程共享的实例。 from sqlalchemy.pool import StaticPool engine = create_engine('sqlite://:memory:', connect_args={'check_same_thread': False}, poolclass=Static ...
  • 自从我将原始sql与sqlalchemy混合以来已经有一段时间了,但无论何时混合使用它们,您都需要了解ORM幕后发生的事情。 首先,检查autocommit标志。 如果未正确配置zope事务,则ORM插入可能会触发提交。 实际上,在查看zope文档后,似乎手动执行语句需要额外的步骤。 从他们的自述文件 : 默认情况下,zope.sqlalchemy会在首次使用会话时将会话置于“活动”状态。 ORM写操作会自动将会话移动到“已更改”状态。 这可以避免不必要的数据库提交。 有时需要通过SQL直接与数据库进行交互 ...
  • 您根本不需要使用add() (只有新对象才需要)。 只需修改现有的page对象然后提交即可。 if 'form.submitted' in request.params: page.title = request.params['title'] page.content = request.params['content'] page.no_idea_what = datetime.now() DBSession.commit() 顺便说一下,除非有充分的理由使用本地时间, ...
  • 要理解为什么会发生这种情况,您需要了解scoped_session和Pool实际上做了什么。 scoped_session保留会话注册表,以便发生以下情况 第一次调用DBSession ,它会在注册表中为您创建一个Session对象 随后,如果满足必要条件(即相同的线程,会话尚未关闭),它不会创建新的Session对象,而是返回先前创建的Session对象 创建Pool ,它会在__init__方法中创建工作__init__ 。 (请注意,在__init__启动工作进程没有任何基础。同样有效的实现可能要等到 ...
  • 您是偶然使用MyISAM表吗? 这适用于InnoDB表,但是具有MyISAM所描述的行为(静默失败以尊重隔离)。 Are you by accident using MyISAM tables? This works fine with InnoDB tables, but would have the described behavior (silent failure to respect isolation) with MyISAM.
  • 我找到了解决方案,它是导致问题的.values(list_of_dictionaries)调用。 这工作: eng = DBSession.get_bind() eng.execute(rbrf_table.insert(), lines) eng.dispose() I found the solution, it's .values(list_of_dictionaries) call that causes the problem. This works: eng = DBSession.ge ...

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。