How to session in TYPO3 and access it globally.

In this blog, you will learn how to set session variable and how to manage it in TYPO3.
In TYPO3, you can create session variable, unset session variable and also can get value just by using $GlOBALS variable.

If you want to create session variable you can create as per below. Here I have set of values in $resultObj variable and I want to set it in session of TYPO3.
Here,
sess - define for session variable
customlogin - my variable to set session values, so that I can get all my values using that variable.
$resultObj - set of value that I am going to assign to my session variable.

Below is the simple code to set session values.

$resultObj = $result;
$GLOBALS['TSFE']->fe_user->setKey('ses', 'customlogin', $resultObj);

Below is the code to retrieve session data.

$userDetails = $GLOBALS['TSFE']->fe_user->sesData['customlogin'];

Below is the code to unset session values.

$GLOBALS['TSFE']->fe_user->setKey('ses', 'customlogin', NULL);

If you have any query, feel free to ask me. Keep reading .. Enjoy!

How to create flex form in extbase extenstion

If you are working with extbase extension development and you're in such a need that you want to provide customization options available from backend only then you can do it using flex form.

In the flex form you can provide many typos of input options as per your need. Like input text, textarea, rich content, likes etc.

For setting flex form you need to do below configuration in your extension. 


$extensionName = t3lib_div::underscoredToUpperCamelCase($_EXTKEY);
$pluginSignature = strtolower($extensionName) . '_pluginnameinsmalllatters';
(In place of  above red highlighted text, you have to put your name of plugin in small latters. )

$GLOBALS['TCA']['tt_content']['types']['list']['subtypes_addlist'][$pluginSignature] = 'pi_flexform';
t3lib_extMgm::addPiFlexFormValue($pluginSignature, 'FILE:EXT:' . $_EXTKEY . '/Configuration/FlexForms/flexform.xml');

(Configuration/FlexForms/flexform.xml is the path to your flex form xml.)



Now, you have to create a folder FlexForms in Configuration folder. Then you have to create flexfom.xml file in FlexForms folder.

For sample flex form, you can use below code :

<t3datastructure>
        <langdisable>1</langdisable>  
  <sheets>
   <sdef>
    <root>
     <tceforms>
      <sheettitle>General Settings</sheettitle>
     </tceforms>
     <type>array</type>
        <el>
                <settings .pageid="">
            <tceforms>
              <exclude>1</exclude>
              <label>Login page</label>
              <config>
                <type>group</type>
                <internal_type>db</internal_type>
                <allowed>pages</allowed>
                <size>1</size>
                <maxitems>1</maxitems>
                <minitems>0</minitems>
                <show_thumbs>1</show_thumbs>
              </config>
            </tceforms>
          </settings>
      </el>
     </root>
    </sdef>
   </sheets>
 </t3datastructure>


Now, you have to clear typo3temp folder (You can use the easy script cleartemp) and clear cache from backend.
You will have a link option in your backend once you use above flex form.

You can get the selected values in flex form by using below code :

$this->settings['pageid']

You can also use other flex form fields. Find more on below link :

http://typo3techie.blogspot.in/search/label/FlexForm

Thanks for reading the post. If you like this post then share with your friends. ENJOY !! :)

findtypo3 : find the code, statement, syntex or anything from your all the files

 findtypo3 :
findtypo3

Download findtypo3.php

System Requirement :
  1. You must need to have Linux or Ubuntu server. This script only work with Linux or Ubuntu server.
  2. You must need TYPO3 setup in proper way. This script is working with almost all TYPO3 versions.
How it works :
  1. Generally in TYPO3 you need to search the code, or Syntex or any text to customize it. I used to change many language specific text but it's very difficult all the time to search that text.
  2. For those people who really want to search and customize it easily, we have a script ready for you. This script will give you the filename with full path for the string you are looking for and it also specify the line Number in that particular file. I think, this make really very easy for typo guys who stuck in finding the text or something and spend lots of hours.
  3. My one of the friend used to ask me to find the string or any text so I think, this gonna help to him and also for similar typo guys.
  4. It have also some options  available like below
    1. search in entire typo3
    2. fileadmin
    3. typo3
    4. typo3conf
    5. typo3temp etc
How to setup :

Below are the simple two steps to setup the findtypo3 script.

1. Downlaod the findtypo3 script and put in your root folder. So it will be like in below image.

2. Goto url of findtypo3.php. So it will be like YOUR-WEBSITE-LINK/findtypo3.php



If you like this script then share with your friends. Enjoy !! :)

cleartemp : Clear TYPO3temp for removing unusal cache file during developing

cleartemp :

Download cleartemp to clear TYPO3temp

Download cleartemp helper to remove TYPO3temp

System Requirement :
  1. You must need to have Linux or Ubuntu server. This script only work with Linux or Ubuntu server.
  2. You must need TYPO3 setup in proper way. This script is working with almost all TYPO3 versions.
  3. 'typo3temp' folder must have 777 permission(full permission).

How it works :
  1. Generally, when we are working with TYPO3 website, we need to clear cache all the time. We can remove basic cache form backend but not all. We also need to delete cache from typo3temp folder. For that, we used to delete all the files from that typo3temp folder to remove all the cache.
  2. It takes around 2-3 minutes when we are working on our local system server. But when we go live it's very difficult to delete all the files from typo3temp. It takes around 15-20 minutes using filezilla or any backend.
  3. Once you setup this script, you just need to enter the URL in the browser and can clear the temp files in just moment.
  4. This script gonna help for the developer who are working with live site and used rename the name of typo3temp folder. Now they can just bookmark this URL and all temp will be cleared easily. 
 How to setup :

It's very easy to set the script. You just need to follow 2 steps.

1.Download the script and extract in in your root directory of your TYPO3 setup. See below screen shot.



2. Goto URL : YOUR-WEBSITE-LINK/cleartemp  . If your website then is http://example.com then your URL will be http://example.com/cleartem. Configure your typo3temp path. Make sure you are setting relative path. We also provide calculate path but if in case it's not correct then configure yourself.


3. Click the Click Now! and you're done.! :)


IN and NOT IN query in TYPO3 extbase extension

When we works with extbase extension development in TYPO3, we have to works with queries.
TYPO3 have their own query builder and it convents the result into object. So whatever we need to user using JOIN query  we can do it just by their object without manual query.

But when I was searching for different queries like IN, NOT IN etc, I was found it difficult to find so I am writing this post.

You can use IN query as per below :

$query = $this->createQuery();
       $query->matching(
               $query->logicalAnd(
                         $query->in('uid', $contrains),
               )
       );
 $query->execute();
You can user NOT IN query as per below :


$query = $this->createQuery();
       $query->matching(
               $query->logicalAnd(
                          $query->logicalNot(
                                   $query->in('uid', $contrains),
                          ) 
               )
       );
 $query->execute();

You can add additional condition of logical AND and logical OR along with above IN and NOT IN query.

Extbase Queries : NOT IN query and Conditional sorting not there


When I was working with extbase extension development, I was wondered about the TYPO3 query builders.
In TYPO3, the query builder create a object and using that object we can get all required related values without any manual join query. But you will only have such object when you use TYPO3 extbase Queries. I found a great blog post on https://lbrmedia.net/codebase/Eintrag/extbase-query-methods/.

1. NOT IN query not there in extbase queries :

When I was working with that, I was in need of a NOT IN Query as we do in Mysql.
Like :

SELECT * FROM 'table1' WHERE  uid NOT IN (SELECT ID FROM table1 WHERE lang = 'FR');

You can use IN Query in TYPO3 like :

$query->in($myProperty, $isInThisObjectOrArray);

But there is no query for NOT IN in TYPO extbase Query. I was in such a need that I want to return values in object only, so stuck in that situation. At the end, I used manual query instead.

2. ORDER BY with specific conditions liks NULL and 0 values not possible in extbase query :
In  TYPO3 extbase queries, you can do sorting by extbase queries as per below :

$query->setOrderings(array("field" => \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_ASCENDING));
$query->setOrderings(array("field" => \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_DESCENDING)

But in case of we need conditional sorting like :

SELECT * FROM my_table WHERE myattr=1 ORDER BY (CASE WHEN districts.id IS NULL then 1 ELSE 0 END),districts.name, schools.name;


Here, I want a conditional sorting in such case not extbase query helped and again, I need to do all using manual query.

Please comment below if you have better solution for the same. :)

How to create own marker in tt_news plugin TYPO3 [GENERIC Markers]


Most of time we have difficulty to add our content in between News Content. Sometimes we need to add  Links in between the news content, sometime we want to add our other dynamic content that we also need to configure from the backend. So that whenever we want to change, we can do just from backend without changes in the tt_ news template files.

Enable or Disable Error Reporting TYPO3

You can enable error reporting in TYPO3 by setting configurations. There are two ways as per below:


1. Using localconf.php

There is a file localconf.php in typo3conf folder. You can add below line in that file.
           
            $TYPO3_CONF_VARS['SYS']['displayErrors'] = '1';                   

Other options :

      1. Do not display PHP errors :

            $TYPO3_CONF_VARS['SYS']['displayErrors'] = '0';     
   
      2. Display errors only if client matches :

            $TYPO3_CONF_VARS['SYS']['displayErrors'] = '2';        

      3. Default setting:

            $TYPO3_CONF_VARS['SYS']['displayErrors'] = '-1';       
 

2. Using .htaccess

 You can add below few lines to enable PHP error reporting.

php_flag display_errors on
php_flag log_errors on
php_value error_log /path/to/php_error.log

TYPO3 FlexForm - Selectbox with Multiple selection Field

 You can use below code to get Selectbox with Multiple selection field in TYPO3 Flex Form:


<label>Selectbox with Multiple selection field</label>

<config>
<type>select</type>
<items type="array">

<numindex index="0" type="array">
<numindex index="0">choice 1</numindex>
<numindex index="1">value 1</numindex>
</numindex>

<numindex index="1" type="array">
<numindex index="0">choice 2</numindex>
<numindex index="1">value 2</numindex>
</numindex>

<numindex index="3" type="array">
<numindex index="0">choice 3</numindex>
<numindex index="1">value 3</numindex>
</numindex>

</items>
<maxitems>3</maxitems>
<size>3</size>
</config>  

TYPO3 FlexForm - Selectbox field

You can use below code to get Selectbox field in TYPO3 Flex Form:


<label>Selectbox with fixed value field</label>
<config>
<type>select</type>
<items type="array">
<numIndex index="0" type="array">
<numIndex index="0">choice 1</numIndex>
<numIndex index="1">value 1</numIndex>
</numIndex>
<numIndex index="1" type="array">
<numIndex index="0">choice 2</numIndex>
<numIndex index="1">value 2</numIndex>
</numIndex>
<numIndex index="3" type="array">
<numIndex index="0">choice 3</numIndex>
<numIndex index="1">value 3</numIndex>
</numIndex>
</items>
</config>