[Solar-talk] use getimagesize() in a view

Rodrigo Moraes rodrigo.moraes at gmail.com
Mon May 12 11:22:18 CDT 2008


Also you can use a static method to return full paths instead of
hardcoding them in your templates, so they become configurable and
available everywhere. Something like...

$image_info = getimagesize(Some_Class::getPath('images/image.jpg'));

    protected $_Some_Class = array(
        'public_path' => 'path/to/somewhere',
    );

    /**
     *
     * Returns the path for a public directory.
     *
     * @param string $path A path to append to the base non-public path.
     *
     * @param string $key A key for the path definition in config.
     *
     * @return string The absolute path for the non-public resources.
     *
     */
    public static function getPath($path = null, $key = 'public_path')
    {
        if (! $base = self::$_public_path[$key]) {
            $base = Solar::config('Some_Class', $key, null);
            $base = $base ? Solar_Dir::fix($base) : Solar_Dir::tmp();
            self::$_public_path[$key] = $base;
        }

        if ($path) {
            $base .= ltrim(Solar_Dir::fix($path), '/');
        }

        return $base;
    }

I over-complicated it, but you can have an idea of how it could be better. :-)

rodrigo


More information about the Solar-talk mailing list