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

3

0

/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');?

Adulthood answered 3/9, 2013 at 10:14 Comment(0)
Y
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.

Yokefellow answered 3/9, 2013 at 13:38 Comment(0)
S
1

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.');
Sideslip answered 3/9, 2013 at 13:35 Comment(0)
Y
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.

Yokefellow answered 3/9, 2013 at 13:38 Comment(0)
G
1

Update: TYPO3_MODE is deprecated in v11 and removed in v12.


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:

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.

Gigigigli answered 12/12, 2019 at 8:27 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.