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
最满意答案
主要的问题是你不能有多个连接到只存在于内存中的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 ofscoped_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 ...
-
将预构建的查询附加到SQLAlchemy中的scoped_session(Attaching a pre-built query to a scoped_session in SQLAlchemy)[2022-06-03]
好的 - 我没有回答所提出的问题,但我似乎确实有一个解决方法。 该问题似乎与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 ...
-
在theading.Thread中使用sqlalchemy scoped_session(Using sqlalchemy scoped_session in theading.Thread)[2022-10-07]
主要的问题是你不能有多个连接到只存在于内存中的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__启动工作进程没有任何基础。同样有效的实现可能要等到 ...
-
锁定sqlalchemy(Locking in sqlalchemy)[2022-10-30]
您是偶然使用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. -
SQLAlchemy Core插入使得(金字塔)范围的会话挂起(SQLAlchemy Core inserts make (Pyramid) scoped session hanging)[2023-04-03]
我找到了解决方案,它是导致问题的.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 ...