TYPO3: when/how to use define('TYPO3_MODE','FE');

六眼飞鱼酱① 提交于 2021-02-11 16:18:15

问题


/public_html/demo is my TYPO3 site, i put a test.php file under it,

<?php
//define('TYPO3_MODE','FE');

require('typo3conf/localconf.php');
require('t3lib/class.t3lib_db.php');
require('t3lib/class.t3lib_div.php');

define('TYPO3_db_host', $typo_db_host);
define('TYPO3_db_username', $typo_db_username);
define('TYPO3_db_password', $typo_db_password);
define('TYPO3_db', $typo_db);


$DB = new t3lib_DB();
$DB->connectDB();
$result = mysql_query("SELECT * FROM fe_users WHERE username='tom_seeker'");
while($row = mysql_fetch_array($result))
{
    echo $row['email'];
}

?>

Question:

when need to put this line: define('TYPO3_MODE','FE');? Here i comment it out, and script still works, so i just wonder when/how to use define('TYPO3_MODE','FE');?


回答1:


There should be no need to define this constant. TYPO3 will do it for you.

Either build a plugin you can put on your site, or an eID that does not need a site to function. Both will give you the TYPO3 environment; the plugin a full one, the eID a smaller (and faster) one.




回答2:


Normally you define the TYPO3_MODE to tell the system if you are in the Frontend or Backend (FE vs BE).

Many Extensions ask the state of TYPO3_MODE.

if (!defined ('TYPO3_MODE'))    die ('Access denied.');



回答3:


The question is quite old but people may still read here searching for answers (as did I).


Your (standalone) script is not running in any TYPO3 context.

The (usual) way is to create an extension using existing TYPO3 API. TYPO3 will do some initialization for you which you then don't have to do yourself, such as autoloading classes, initializing backend and frontend users, language handling, resolving of URLs etc.

If you do this, TYPO3_MODE will already be initialized. Read more about TYPO3_MODE in the Constants section. Note that most TYPO3 constants are being deprecated and have been replaced by the Environment class.

Read more about how to create an extension:

  • Introduction to the Extension Architecture
  • Namespaces
  • Autoloading

With the latest TYPO3 10 version, this is what you might do:

  1. Decide to either create an extension (in the directory typo3conf/ext/extensinoname) from scratch or using the extension_builder (The extension_builder generates extension code for you. This is based on the Extbase framework and the Fluid templating engine. In many cases, this may be overkill.)
  2. If you create from scratch, you must create the minimum required files ext_emconf.php and composer.json
  3. Continue from there (depending on what you are trying to do). For the usecase above, you will most likely want to create a plugin. And you will want to fetch database records (using QueryBuilder based on Doctrine dbal or Extbase persistence) or use the existing FrontendUserRepository from the TYPO3 core.

What you are trying to do above, may not even require an extension.

  • If you just want to provide an FE login, you can use existing functionality
  • For authentication, you can extend existing functionality


来源:https://stackoverflow.com/questions/18589663/typo3-when-how-to-use-definetypo3-mode-fe

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!