0

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>
}   
}
Taryn
  • 242,637
  • 56
  • 362
  • 405
Thomas BP
  • 1,187
  • 3
  • 26
  • 62
  • **Firstly**, ask yourself if you really need your own PHP method to retrieve data from the databse. Wouldn't the `CONTENT` or `RECORDS` objects do the trick? **Secondly**, you should never attempt to output content with `echo` or `print` unless your are debugging something. Your method is expected to `return` the output. **Thirdly**, to output content where a particular content element is, you will have to tie it with that content, depending on your requirements. – tmt Oct 07 '13 at 09:20
  • What's wrong with `echo` or `print`, @cascaval? I do it all the time in proper PHP templates. – maryisdead Oct 10 '13 at 14:10
  • @maryisdead: I wasn't talking generally about PHP projects but about TYPO3 only. The methods are expected to return the value because TYPO3 needs to place it in the right spot of the outputed code. Also, it's subject to further post-processing (e.g. in HTML Tidy) and caching. – tmt Oct 10 '13 at 15:23
  • Ah, my bad then, sorry! You're of course right then. :-) – maryisdead Oct 10 '13 at 16:47

2 Answers2

0

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.

lorenz
  • 4,538
  • 1
  • 27
  • 45
0

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.

lorenz
  • 4,538
  • 1
  • 27
  • 45
  • Okay im getting a better and better understanding, so what u say is (u dont say it), that i make a FLUID template to every single page, so every page have its own FLUID template, and then im working in the template and add the F-tags in it. – Thomas BP Oct 10 '13 at 07:58