Flourish PHP Unframework
This is an archived copy of the forum for reference purposes

acces file name

posted by mungiu 9 years ago

how can i acces file name something like this.

foreach($banner_doi as $banner) {
						$xtpl->assign("link_banner_doi", $banner->getMedia()->getName());
}
Bannere Object
(
    [cache:protected] => Array
        (
        )

    [old_values:protected] => Array
        (
        )

    [related_records:protected] => Array
        (
        )

    [values:protected] => Array
        (
            [id_bannere] => 1
            [titlu] => Primul banner
            [media] => fFile Object
                (
                    [current_line:fFile:private] => 
                    [current_line_number:fFile:private] => 
                    [deleted:protected] => 
                    [file:protected] => G:\\xampp\\htdocs\\cd\\uploads\\bannere\\structura_site_c_d-1_copy1.docx
                    [file_handle:fFile:private] => 
                )

            [este_activ] => on
            [limba] => romana
            [data] => fDate Object
                (
                    [date:fDate:private] => 1280178000
                )

        )

)

i figure out working like this but when the filedoesn't exist on the server it not return an object and get error.

posted by mungiu 9 years ago

How can i do to not receive an error, maybe trwing an catchable error if the file not existing on the server.

posted by mungiu 9 years ago

I would probably write a custom method to do what you describe. I used to have Flourish do that internally, but it caused exceptions to be thrown when a record was being loaded from the session. The following code should work for your situation.

class NoFileException extends fExpectedException { }

class Banner extends fActiveRecord
{
    public function getMedia()
    {
        // You have to make a call to __call() in order for the fORMFile plugin
        // to be able to intercept the method call
        $media = $this->__call('getMedia', array());
        if ($media instanceof fFile) {
            return $media;
        }
        throw new NoFileException('The file, %s, could not be found on the filesystem', $media);
    }
}
posted by wbond 9 years ago