HOW TO ZIP??

For Joomla! 1.5 Coding related discussions, please use: http://groups.google.com/group/joomla-dev-general
Forum rules
Please use the mailing list here: http://groups.google.com/group/joomla-dev-general rather than this forum.
Locked
hjortsberg
Joomla! Explorer
Joomla! Explorer
Posts: 359
Joined: Sun Jun 22, 2008 4:25 pm

HOW TO ZIP??

Post by hjortsberg » Wed Aug 22, 2012 8:56 pm

I have a function in my controller where I zip files, it works.
Now I am trying to move the function to a view.

But I can't figure out what I am doing wrong!!!
I have been trying for days now!!

I have

Code: Select all

$folderzzz = 'tmp'.DS.str_replace("-", "_", $this->that).'_'.JUtility::getToken().DS;
					$zip_fileszzz = JFolder::files( $folderzzz, '.zip', false, false, '' );
					$archive_file_namezzz = JPATH_ROOT.DS.$folderzzz.'other_'.str_replace("-", "_", $this->that).'_'.JUtility::getToken().'.zip';
                    $excludeszzz = array('zip');
					$fileszzz = JFolder::files( $folderzzz, '.', false, false, $excludeszzz );
                    $zipAdapter = JArchive::getAdapter('zip');
                    $filesArrayzzz = array();
					
                    foreach($fileszzz as $filezzz)
                    {						
						$datazzz = JFile::read($folderzzz.$filezzz);
						$filesArrayzzz[] = array('name' => $filezzz, 'data' => $datazzz);
						//JFile::delete($folder.$file);							
                    }
					if ( !$zipAdapter->create( $archive_file_name, $filesArray, array()) )
                    {
                        $mainframe->enqueueMessage('Can not create zipfile.', 'message');
                    }
I have tried to include, just to be safe, all

Code: Select all

jimport('joomla.filesystem.file');
					jimport('joomla.filesystem.archive');
					jimport('joomla.filesystem.archive.zip');
					jimport('joomla.filesystem.folder');
(does that matter?)

The only thing I get is

Code: Select all

Fatal error: Class 'JArchive' not found in /customers/0/7/5/mysite.com/httpd.www/components/com_mycomponent/views/download/view.thisfilezip.php on line 135 
and the line

Code: Select all

$zipAdapter = JArchive::getAdapter('zip');
is on that line...

I won't have any hair left soon, and if I have, it will be gray!

I will be thankful for the rest of my life if someone find my stupidity!

grayz
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 128
Joined: Tue Dec 12, 2006 8:37 pm

Re: HOW TO ZIP??

Post by grayz » Sun Sep 23, 2012 9:36 pm

'JArchive' class should be imported by
jimport( 'joomla.filesystem.archive' );

However, it's better to keep this function in controller, not view.
www.justPHP.net - HACKS for Hot Property, Custom 404 Error Pages, Templates for Joomla etc.
Developing: www.zerno.org.ua

hjortsberg
Joomla! Explorer
Joomla! Explorer
Posts: 359
Joined: Sun Jun 22, 2008 4:25 pm

Re: HOW TO ZIP??

Post by hjortsberg » Mon Sep 24, 2012 1:08 pm

That may be true!

But I am having a BIG controller file right now...
I have a lot of mail functions, archive functions and many, many other functions in my controller...

I must move them to views so that the bog controller file don't load every time...

Or do you have any other solution for me?

grayz
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 128
Joined: Tue Dec 12, 2006 8:37 pm

Re: HOW TO ZIP??

Post by grayz » Mon Sep 24, 2012 1:13 pm

According to MVC model, controller should keep functions which respond to user's actions. Models are the better place to put functions which process data.
Moreover, some functions (if they are common for several models) can be moved in separate helper.php file.
www.justPHP.net - HACKS for Hot Property, Custom 404 Error Pages, Templates for Joomla etc.
Developing: www.zerno.org.ua


Locked

Return to “Joomla! 1.5 Coding”