简体   繁体   中英

TYPO3 include PHP function and SQL query

Have search the net, but can't find any fix/help.

Im running TYPO3 v.6. Extbase/Fluid im trying to do 2 things.

  1. Including a php page, and show it in a content element on a page.
  2. trying to get some data from a MySQL db, and show it in a content element.

I have included a php page in a TS page like.

lib.timmers = USER_INT
lib.timmers {
includeLibs.time = fileadmin/templates/add/php/dates.php
    userFunc = custom_class->customfunction
}

And have then installed the Extension tscobj, its working with Return commands in the PHP page, but not with Echo and Print. If i take the includeLibs.time and place it outside the lib.timmer, then it shows the php content, but before the HTML tag..

So i have problems getting included php content inside a content element on a page.

And How can I add a MySQL connection and make some HTML code/layout, so i can get records from a DB inside a content element, i have tryed the extension ViewHelper, but its not working.

Can someone help me.

Edit:

I have tryed this code, but im not getting any data..

lib.GetMainCat = CONTENT
lib.GetMainCat {
wrap = <div class="p_filter"><div class="p_filter_container"><a class="p_cat_filter button" href="#" title="All Categories" data-filter="article.portfolio"><span>All Categories</span></a><ul class="p_filter"><li class="current"><a href="#" title="All Categories" data-filter="article.portfolio">All Categories</a></li>|</ul></div><div class="cl"></div></div>
table = tx_tbpdrills_domain_model_drillcategory

select {
    selectFields = *
            where = NOT deleted AND NOT hidden      
    orderBy = categorytitle ASC
}
renderObj >
renderObj = COA_INT
renderObj {     
    10 = TEXT       
    10.field = categorytitle
    10.wrap = <li><a href="#" title="###" data-filter="article.portfolio[data-category~='###']">|</a></li>
}   
}

So why do you want to use print() or echo() to return your content? These constructs output some content at runtime so the output will be before the whole TYPO3 output.

Just throw your content to a variable like $content and then use return $content in your user function.

Somehow or other I think it would be better for you to kickstart an own extension where you will have the full TYPO3 API available. Do you want to connect to the same MySQL database your TYPO3 is located? Please clarify what you wish to do, then I will edit my answer to point you to the right direction.

You don't need to set selectFields = * because it's the default. Most likely you forgot to set the pidInList because if it's not set it uses the pid of the current page.

It could work that way:

lib.GetMainCat = CONTENT
lib.GetMainCat {
    wrap = <div class="p_filter"><div class="p_filter_container"><a class="p_cat_filter button" href="#" title="All Categories" data-filter="article.portfolio"><span>All Categories</span></a><ul class="p_filter"><li class="current"><a href="#" title="All Categories" data-filter="article.portfolio">All Categories</a></li>|</ul></div><div class="cl"></div></div>
    table = tx_tbpdrills_domain_model_drillcategory
    select {
        pidInList = 999 [page id where the records reside]
        where = NOT deleted AND NOT hidden      
        orderBy = categorytitle ASC
    }
    renderObj = COA_INT
    renderObj {     
        10 = TEXT       
        10.field = categorytitle
        10.wrap = <li><a href="#" title="###" data-filter="article.portfolio[data-category~='###']">|</a></li>
    }   
}

This object can now be accessed in TypoScript:

page.20 < lib.GetMainCat

Or in a Fluid template:

<f:cObject typoscriptObjectPath="lib.GetMainCat" />

The core doesn't ship a method to use a TypoScript object in a content element. If you want to place your TypoScript object just like a content element, you will need to use an extension like http://typo3.org/extensions/repository/view/tscobj It's quite old, but it should still work. This is the fastest, but probably not the best solution.

You could write an own plugin that basically includes this TypoScript object. Or you could use another Fluid partial or template to include it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM