ContentElement for cd_collection module?
Hi all,
it seems to be difficult to get some staring infos/tips in that topic here....
I have created a module based on the great cd_collection tutorial.
What i want to do now is to create a module (with content-element?) to realize the following:
- create a new page in the BE.
- choose one of the cds.
- then a page is rendered with the cd details.
So i think, i need a BE module that let me select a cd from the 'tl_cds' table.
Then i need another 'item' (a FE module, a ContentElement?) that takes that record from the DB & renders an 'article' probably...
I think, i can handle to create a BE Module that selects a cd from the 'tl_cds' table. But then, how to go on from here?
I really would appreciate some hints tips & pointers where to look into...
Thank you in advance.
with kind regards,
Karl
Re: ContentElement for cd_collection module?
You should use the list/reader paradigm to list CDs. The list would list CDs and generate links to the reader page with
=> cdreaderpage/items/cd-alias-goes-here.html
There should then be two modules:
CD List Module
CD Reader Module
You can then also insert these modules as CE's using the CE Module link.
Making a module to list 1 item would not be effective.
Re: ContentElement for cd_collection module?
Just as the Thyon said, but if you followed my tutorial it would be much easier to use ID instead of alias, to load specified CD. However, if you would like to follow the alias way, you can take a look at News Reader module and see how it's done.
Re: ContentElement for cd_collection module?
Wow!
Thank you for that, Thyon & Tru!
After looking into the Catalog-System, i must admit that this is very complex for me newbie & the purpose of learning Contao. I am not yet too familiar with php (my last php experience dates from v3.x.... in 2002).
Isn't there a more 'accessible' way to enhance the cd_collection sample?
There must be a quite simple way to create a module/contentelement to choose a cd from the collection & display the details nicely in HTML...
can i do that completely in a FE module? That is, choose a record via a (SELECT * FROM tl_cds WHERE id=...) and display the returned data via Template?
Again, Thank you in advance for your appreciated help!
- Karl
Re: ContentElement for cd_collection module?
uff....
I finally succeeded to get my first basic Contao thing to work.
That is, i now have a CD Collection Module that i use to manage the DB-Table in the BE.
Then i have a ContentElement that displays the cd details through the associated template.
The only quirk is that i did not succeed to build a CE that populates a select-control with the entries in my cd collection table so that i choose from them.
I assume that i have to 'subclass' one of the "select" fields from tl_content and define a 'options_callback'...
but how to do this?
My quirk for now is that i have a textbox that i have to input the 'title' of a cd into. Then that title is used in a
(select * from tl_cds where title='". $this->text . "'") to get the details.
As a base, i took the good tutorial from Andreas Zeiser at http://www.az13.de/2010/03/11/typolight ... stellen-i/
Thanks, Andreas. A very accessible tutorial :)
So if needed i will post a new question on the forum.
Thank you all for you help,
Karl
Re: ContentElement for cd_collection module?
Ok, a little hint.
Create new files ModuleCdList.php and ModuleCdReader.php in /system/modules/cd_collection/:
ModuleCdList.php
[code=php:ptm8r7li]<span class="syntaxdefault">
</span><span class="syntaxkeyword">protected*function*</span><span class="syntaxdefault">compile</span><span class="syntaxkeyword">()
{
****</span><span class="syntaxcomment">//*Get*current*"jumpTo"*page
****</span><span class="syntaxdefault">$objPage*</span><span class="syntaxkeyword">=*</span><span class="syntaxdefault">$this</span><span class="syntaxkeyword">-></span><span class="syntaxdefault">Database</span><span class="syntaxkeyword">-></span><span class="syntaxdefault">prepare</span><span class="syntaxkeyword">(</span><span class="syntaxstring">"SELECT*id,*alias*FROM*tl _page*WHERE*id=?"</span><span class="syntaxkeyword">)
************-></span><span class="syntaxdefault">limit</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">1</span><span class="syntaxkeyword">)
************-></span><span class="syntaxdefault">execute</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">$this</span><span class="syntaxkeyword">-></span><span class="syntaxdefault">jumpTo</span><span class="syntaxkeyword">);
****</span><span class="syntaxdefault">$strHref*</span><span class="syntaxkeyword">=*</span><span class="syntaxdefault">$this</span><span class="syntaxkeyword">-></span><span class="syntaxdefault">generateFrontendUrl</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">$objPage</span><span class="syntaxkeyword">-></span><span class="syntaxdefault">row</span><span class="syntaxkeyword">());
****</span><span class="syntaxdefault">$objCds*</span><span class="syntaxkeyword">=*</span><span class="syntaxdefault">$this</span><span class="syntaxkeyword">-></span><span class="syntaxdefault">Database</span><span class="syntaxkeyword">-></span><span class="syntaxdefault">execute</span><span class="syntaxkeyword">(</span><span class="syntaxstring">"SELECT*id,*title*FROM*tl _cds"</span><span class="syntaxkeyword">);
****while*(</span><span class="syntaxdefault">$objCds</span><span class="syntaxkeyword">-></span><span class="syntaxdefault">next</span><span class="syntaxkeyword">())
****{
******</span><span class="syntaxdefault">$arrCds</span><span class="syntaxkeyword">[]*=*array
******(
********</span><span class="syntaxstring">'title'*</span><span class="syntaxkeyword">=>*</span><span class="syntaxdefault">specialchars</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">$objCds</span><span class="syntaxkeyword">-></span><span class="syntaxdefault">title</span><span class="syntaxkeyword">),
********</span><span class="syntaxstring">'href'*</span><span class="syntaxkeyword">=>*</span><span class="syntaxdefault">$strHref*</span><span class="syntaxkeyword">.*</span><span class="syntaxstring">'?cd='*</span><span class="syntaxkeyword">.*</span><span class="syntaxdefault">$objCds</span><span class="syntaxkeyword">-></span><span class="syntaxdefault">id
******</span><span class="syntaxkeyword">);
****}
****</span><span class="syntaxdefault">$this</span><span class="syntaxkeyword">-></span><span class="syntaxdefault">Template</span><span class="syntaxkeyword">-></span><span class="syntaxdefault">cds*</span><span class="syntaxkeyword">=*</span><span class="syntaxdefault">$arrCds</span><span class="syntaxkeyword">;
}
**</span><span class="syntaxdefault"></span>[/code:ptm8r7li]
ModuleCdReader.php
[code=php:ptm8r7li]<span class="syntaxdefault">
</span><span class="syntaxkeyword">protected*function*</span><span class="syntaxdefault">compile</span><span class="syntaxkeyword">()
{
****</span><span class="syntaxdefault">$intId*</span><span class="syntaxkeyword">=*(int)*</span><span class="syntaxdefault">$this</span><span class="syntaxkeyword">-></span><span class="syntaxdefault">Input</span><span class="syntaxkeyword">-></span><span class="syntaxdefault">get</span><span class="syntaxkeyword">(</span><span class="syntaxstring">'cd'</span><span class="syntaxkeyword">);
****</span><span class="syntaxdefault">$objCd*</span><span class="syntaxkeyword">=*</span><span class="syntaxdefault">$this</span><span class="syntaxkeyword">-></span><span class="syntaxdefault">Database</span><span class="syntaxkeyword">-></span><span class="syntaxdefault">prepare</span><span class="syntaxkeyword">(</span><span class="syntaxstring">"SELECT***FROM*tl_cds*WHE RE*id=?"</span><span class="syntaxkeyword">)-></span><span class="syntaxdefault">limit</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">1</span><span class="syntaxkeyword">)-></span><span class="syntaxdefault">execute</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">$intId</span><span class="syntaxkeyword">);
****</span><span class="syntaxdefault">$this</span><span class="syntaxkeyword">-></span><span class="syntaxdefault">Template</span><span class="syntaxkeyword">-></span><span class="syntaxdefault">setData</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">$objCd</span><span class="syntaxkeyword">-></span><span class="syntaxdefault">row</span><span class="syntaxkeyword">());
}
**</span><span class="syntaxdefault"></span>[/code:ptm8r7li]
Now you need to alter the DCA of tl_module to add redirect selection:
/system/modules/cd_collection/dca/tl_module.php
[code=php:ptm8r7li]<span class="syntaxdefault">
$GLOBALS</span><span class="syntaxkeyword">[</span><span class="syntaxstring">'TL_DCA'</span><span class="syntaxkeyword">][</span><span class="syntaxstring">'tl_module'</span><span class="syntaxkeyword">][</span><span class="syntaxstring">'palettes'</span><span class="syntaxkeyword">][</span><span class="syntaxstring">'cds_list'</span><span class="syntaxkeyword">]*=*</span><span class="syntaxstring">'{title_legend},name,headline ,type;{redirect_legend},jumpTo;{expert_legend:hide },cssID,space'</span><span class="syntaxkeyword">;
**</span><span class="syntaxdefault"></span>[/code:ptm8r7li]
Don't forget to register both modules in config:
/system/modules/cd_collection/config/config.php
[code=php:ptm8r7li]<span class="syntaxdefault">
array_insert</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">$GLOBALS</span><span class="syntaxkeyword">[</span><span class="syntaxstring">'FE_MOD'</span><span class="syntaxkeyword">][</span><span class="syntaxstring">'miscellaneous'</span><span class="syntaxkeyword">],*</span><span class="syntaxdefault">0</span><span class="syntaxkeyword">,*array
(
****</span><span class="syntaxstring">'cds_list'***</span><span class="syntaxkeyword">=>*</span><span class="syntaxstring">'ModuleCdList'</span><span class="syntaxkeyword">,
****</span><span class="syntaxstring">'cds_reader'*</span><span class="syntaxkeyword">=>*</span><span class="syntaxstring">'ModuleCdReader'
</span><span class="syntaxkeyword">));
**</span><span class="syntaxdefault"></span>[/code:ptm8r7li]
And I guess that should work...
Re: ContentElement for cd_collection module?
Hi,
First Tru - I love your posts on your blog and you have allready helped me get a basic understanding of what's needed for creating a custom module in Contao - thanks for your time and your posts!.
I'm trying to do the same as karltietze - ie. trying to learn how to put data into the database with contao and then pull it out from the Contao backend or frontend. In my case I have a very very bare bones understanding of Php. Your cd collection module as a guideline, shows nicely how the Contao extention module system works with Php.
Exactly in the same way that as in your guide, we use a backend module to write categories and to write specific records, I want to be able to use a backend module to read categories and read specific records also. A kind of ‘in and out’ tour of Contao if you will ?
With your CD module we have a very clear model for understanding how to write to the database. I do feel though, that I have only a very limited understanding of how to read data from the Contao database with my new module.
As an educational model, It would be great if we could see how to choose specific records for display by using a backend module. I feel that this is a basic need for all kinds of situations and I would love to have control of it.
Your guide is the best and I am the closest I have come to understanding how to do this.
I have tried modifying a few other extentions to get this functionality, and then realised that the news module was working closest to what I needed. By looking at the news module, I allready realised there were the extra list and reader modules and also that I needed a tl_module file in the dca folder to extend the module in the back end.
Using a modified news module, I still have no control over single news items and I have no idea which field to create to get a list of child records back with checkboxes in the backend.
By trying your suggestion - I realise ModuleCdList and ModuleCdReader are probably missing classes. I think also that tl_module needs several fields, and that there needs to be a template also - but I'm not sure how to go about any of it really.
I realise there is an extensive developer guide for this, but I'm not really a developer.
Any chance of giving us PHP beginners a simplified working model we can study?