0
votes

I am quite new to TYPO3, I am inspecting a code for errors and I saw a non working href. the inspection in the browser shows empty href :

<a class="download" target="_blank" title="Initiates file download" href=""> here..</a>

The code is :

<a class="download" target="_blank" title="Initiates file download" href="{location.pdf.originalResource.publicUrl}"><f:translate key="tx_locations_domain_model_location.here" />..</a>

I don't understand this location.pdf.originalResource.publicUrl !! When I display {location} I get : Locations\Locations\Domain\Model\Location:102 I can't find such path in my folders !! What am I missing !!

When I make

<f:debug>{location}</f:debug>

I see : pdf => NULL , how can I fix it, in my backend I select a PDF and saved. no error message UPDATE: My Pdf field is int(11) unsigned, Here is my TCA (typo3conf/ext/locations/Configuration/TCA/Location.php)

$GLOBALS['TCA']['tx_locations_domain_model_location'] = array(
....
    'columns' => array(
....
    'pdf' => array(
        'exclude' => 1,
        'label' => 'LLL:EXT:locations/Resources/Private/Language/locallang_db.xlf:tx_locations_domain_model_location.pdf',
        'config' => array (                             
            'type' => 'group',
            'internal_type' => 'file',
            'allowed' => $GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'],
            'max_size' => $GLOBALS['TYPO3_CONF_VARS']['BE']['maxFileSize'],
            'uploadfolder' => 'uploads/pics',
            'show_thumbs' => 1,
            'size' => 1,
            'minitems' => 0,
            'maxitems' => 1
        )
    ),

here is my Location class :

<?php
namespace Locations\Locations\Domain\Model;

/**
 * Location
 */
class Location extends \TYPO3\CMS\Extbase\DomainObject\AbstractEntity {

    /**
     * title
     *
     * @var string
     */
    protected $title = '';

    /**
     * fullTitle
     *
     * @var string
     */
    protected $fullTitle = '';

    /**
     * description
     *
     * @var string
     */
    protected $description = '';

    /**
     * image
     *
     * @var \TYPO3\CMS\Extbase\Domain\Model\FileReference
     */
    protected $image = NULL;


    /**
     * secondTitle
     *
     * @var string
     */
    protected $secondTitle = '';

    /**
     * secondDescription
     *
     * @var string
     */
    protected $secondDescription = '';

    /**
     * address
     *
     * @var string
     */
    protected $address = '';

    /**
     * howToGetIt
     *
     * @var string
     */
    protected $howToGetIt = '';

    /**
     * thirdTitle
     *
     * @var string
     */
    protected $thirdTitle = '';

    /**
     * thirdDescription
     *
     * @var string
     */
    protected $thirdDescription = '';

    /**
     * googleMap
     *
     * @var string
     */
    protected $googleMap = '';


    /**
     * pdf
     *
     * @var \TYPO3\CMS\Extbase\Domain\Model\FileReference
     */
    protected $pdf = NULL;


    /**
     * pricingtpl
     *
     * @var int
     */
    protected $pricingtpl;

    /**
     * category
     *
     * @var \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\Locations\Locations\Domain\Model\Category>
     */
    protected $category = NULL;

    /**
     * __construct
     */
    public function __construct() {
        //Do not remove the next line: It would break the functionality
        $this->initStorageObjects();
    }

    /**
     * Initializes all ObjectStorage properties
     * Do not modify this method!
     * It will be rewritten on each save in the extension builder
     * You may modify the constructor of this class instead
     *
     * @return void
     */
    protected function initStorageObjects() {
        $this->category = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage();
    }

    /**
     * Returns the title
     *
     * @return string $title
     */
    public function getTitle() {
        return $this->title;
    }


    /**
     * Sets the image
     *
     * @param \TYPO3\CMS\Extbase\Domain\Model\FileReference $image
     * @return void
     */
    public function setImage(\TYPO3\CMS\Extbase\Domain\Model\FileReference $image) {
        $this->image = $image;
    }


    /**
     * Sets the pdf
     *
     * @param \TYPO3\CMS\Extbase\Domain\Model\FileReference $pdf
     * @return void
     */
    public function setPdf(\TYPO3\CMS\Extbase\Domain\Model\FileReference $pdf) {
        $this->pdf = $pdf;
    }


    /**
     * Removes a Category
     *
     * @param \Locations\Locations\Domain\Model\Category $categoryToRemove The Category to be removed
     * @return void
     */
    public function removeCategory(\Locations\Locations\Domain\Model\Category $categoryToRemove) {
        $this->category->detach($categoryToRemove);
    }

    /**
     * Returns the category
     *
     * @return \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\Locations\Locations\Domain\Model\Category> $category
     */
    public function getCategory() {
        return $this->category;
    }

    /**
     * Sets the category
     *
     * @param \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\Locations\Locations\Domain\Model\Category> $category
     * @return void
     */
    public function setCategory(\TYPO3\CMS\Extbase\Persistence\ObjectStorage $category) {
        $this->category = $category;
    }



}
2
If you get pdf => NULL and you did attach a file in BE it means your data mapping doesn‘t work. Can you post your TCA for field pdf and you Location model? - undko
hmmm, that's a bit advanced to me, could you tell me what to do exactly ? (what is TCA ?) - user2997418
Read up a bit about TCA! In your case it‘s content of file EXT:locations/Configuration/TCA/tx_locations_domain_model_location.php. - undko

2 Answers

0
votes

Your model Location.php file. You can't define getPdf() method only use set method. Please define first getPdf() method in your Location.php file.

Like this.

 /**
 * Returns the pdf
 *
 * @return \TYPO3\CMS\Extbase\Domain\Model\FileReference $pdf
 */
public function getPdf() {
    return $this->Pdf;
}

After you can debug your .html file like this <f:debug>{_all}</f:debug> and see the debug output.

0
votes

You don't have to use in Fluid things like <a href=""/>, you can find the <f:link..>, <f:uri..>,etc, in fluid documentation for generating links.

But there for file downloading you have to use this viewhelper. You have to know only the uid of the file. In your case {location.pdf.uid} Be sure that you have indexed files before use it.

<v:resource.file additionalAttributes="{foo: 'bar'}" data="{foo: 'bar'}" identifier="[mixed]" categories="[mixed]" treatIdAsUid="1" treatIdAsReference="1" as="NULL">
    <!-- tag content - may be ignored! -->
</v:resource.file>