Zend_Form with Zend_Validate with Zend_File_Transfer

How to build form using ini files.
Example includes Zend_Form elements, Zend_Validate and File uploads using Zend_File_Transfer.

Protected method to retrieve form config and fill data into selectbox.

protected function prepareProductForm()
{
$form = new Application_Form( ‘admin/product’ );

$categories = array( ‘Select Category’ );
foreach( Application_Category::getCategories() as $category )
{
$categories[$category->categoryId] = $category->name;
}

$form->getElement( ‘categoryId’ )->setMultiOptions( $categories );

return $form;
}

This method will render form from and handle submits. Will check for uploaded files.

public function productAction()
{
$form = $this->prepareProductForm();
$product = array();

if ( $this->getRequest()->isPost() )
{
$product = new Application_Product(
array(
‘productId’ => $this->getRequest()->getParam( ‘productId’ ),
‘name’ => $this->getRequest()->getParam( ‘name’ ),
‘description’ => $this->getRequest()->getParam( ‘description’ ),
‘categoryId’ => $this->getRequest()->getParam( ‘categoryId’ ),
‘resellerPrice’ => $this->getRequest()->getParam( ‘resellerPrice’ )
)
);

if ( !$form->isValid( $this->getRequest()->getPost() ) )
{
$this->view->errorMessages = array( “Validation Error” );
}

/*
* Receiving files
*/
if ( !$form->photos->receive() || !$form->photom->receive() || !$form->photol->receive() )
{
$this->view->errorMessages = array( “Upload error” );
}

if ( count( $this->view->errorMessages ) <= 0 )
{
try {
$product->save();
$this->view->message = “User successfully updated”;
}
catch ( Application_Service_Exception $ex )
{
$this->view->errorMessages = array( $ex->getMessage() );
}
}

$product = $product->toArray();
}
elseif ( $this->getRequest()->getParam( ‘id’ ) )
{
$product = Application_Service::getInstance()->getProduct( $this->getRequest()->getParam( ‘id’ ) );
}

$form->populate( $product );
$this->view->form = $form;
}

Ini file defining form containing elements.

# Product

admin.product.method = post
admin.product.options.description = ‘Create Product’

admin.product.elements.productId.type = hidden

admin.product.elements.name.type = text
admin.product.elements.name.options.label = “Product Name”
admin.product.elements.name.options.required = true

admin.product.elements.photos.type = file
admin.product.elements.photos.options.label = “Photo S”
admin.product.elements.photos.options.description = “( 100×110 ) Shown on Front page. Only jpg,png,gif formats supported”
admin.product.elements.photos.options.destination = APPLICATION_PATH “/../public/images/product”
admin.product.elements.photos.options.validators.extension.validator = Extension
admin.product.elements.photos.options.validators.extension.options.extension = “jpg,png,gif”
admin.product.elements.photos.options.validators.imagesize.validator = ImageSize
admin.product.elements.photos.options.validators.imagesize.width = 100
admin.product.elements.photos.options.validators.imagesize.height = 110

admin.product.elements.photom.type = file
admin.product.elements.photom.options.label = “Photo M”
admin.product.elements.photom.options.description = “( 180×250 ) Shown on Auction Info Page. Only jpg,png,gif formats supported”
admin.product.elements.photom.options.destination = APPLICATION_PATH “/../public/images/product”
admin.product.elements.photom.options.validators.extension.validator = Extension
admin.product.elements.photom.options.validators.extension.options.extension = “jpg,png,gif”
#admin.product.elements.photom.options.validators.imagesize.validator = ImageSize
#admin.product.elements.photom.options.validators.imagesize.options.width = 180
#admin.product.elements.photom.options.validators.imagesize.options.height = 250

admin.product.elements.photol.type = file
admin.product.elements.photol.options.label = “Photo L”
admin.product.elements.photol.options.description = “( 250×450 ) Shown on … Only jpg,png,gif formats supported”
admin.product.elements.photol.options.destination = APPLICATION_PATH “/../public/images/product”
admin.product.elements.photol.options.validators.extension.validator = Extension
admin.product.elements.photol.options.validators.extension.options.extension = “jpg,png,gif”
admin.product.elements.photol.options.validators.imagesize.validator = ImageSize
admin.product.elements.photol.options.validators.imagesize.width = 250
admin.product.elements.photol.options.validators.imagesize.height = 450

admin.product.elements.description.type = textarea
admin.product.elements.description.options.label = “Description”
admin.product.elements.description.options.cols = 50
admin.product.elements.description.options.rows = 8

admin.product.elements.resellerPrice.type = text
admin.product.elements.resellerPrice.options.label = “Reseller Price”
admin.product.elements.resellerPrice.options.required = true

admin.product.elements.categoryId.type = select
admin.product.elements.categoryId.options.label = “Category”
admin.product.elements.categoryId.options.required = true

admin.product.elements.submit.type = submit
admin.product.elements.submit.options.label = “Save”

Magento 1.4 upgrade - Missing Yesnocustom.php

After upgrade from 1.3.2.4 to 1.4.0.1 using MagentoConnect we got exception in Admin/System page.

After checks we have figured out that the file was missing in upgrade package for Magento Core Modules.

File was used by system.xml located in Mage/Core/etc/.

In order to fix this you have to download Magento package 1.4.0.1 from website and add missing file to your sources

app/code/core/Mage/Adminhtml/Model/System/Config/Source/Yesnocustom.php

Magento :: Invalid mode for clean() method

After upgrade Magento to 1.4.0.1 I’ve got such an error.

The problem is that Varien did not managed to add removal deprecated code/files which overrides Zend’s code.

In order to fix this problem you have to remove folder:

app/code/core/Zend/Cache

Upgrading subversion client to 1.6.x for Ubuntu 8.04 hardy

Tortoise SVN and other IDE integrated subversion clients was changing format of .svn/* files so that was not possible to use command line subversion client which is more secure.

Finally got upgraded subversion client for Ubuntu Hardy (8.04).

1. Copy source list from: https://launchpad.net/~anders-kaseorg/+archive/subversion-1.6

2. Add lists to /etc/apt/sources.list at bottom of file - Save file

3. apt-get install subversion

(Here I had asked to confirm not authenticated installation)

4. svn status

MyDNS Starts Before Mysql

In order to force mydns start after mysql execute following:

cd /etc/rc.d/rc3.d
mv S52mydns S99mydns
cd /etc/rc.d/rc4.d
mv S52mydns S99mydns
cd /etc/rc.d/rc5.d
mv S52mydns S99mydns

See: http://www.howtoforge.com/installing-mydns-mydnsconfig-centos-5.1-p2
Also: http://www.centos.org/docs/5/html/Installation_Guide-en-US/s1-boot-init-shutdown-sysv.html

Drupal node access

How to restrict editing of verified content?
node_access is not called. It’s required to define node types from modules in order to have node_access hook be called.

Drupal Views - Right Join issue

Currently we are experiencing problem with drupal views.
We need to right join two entities.

ExtJs - Form field description and tips

The problem is that ExtJs is not presume field description at all.

There are Label component which can be used as field description.

Label component can be linked to particular so that formfield will be focused when label (description) clicked.

extjs-form-field-description

How to use svnignore!

1. Settings svn:ignore property

svn propset svn:ignore “*” folder1/
svn propset svn:ignore “*” folder2

2. Commit to apply changes.

svn ci -m “Data in these folders will be ignored by svn”

Source: http://www.devcha.com/2008/02/how-to-make-svn-ignore-some-folders.html

Magento and ExtJs

We are going to use in our huge auction project Magento Commerce Community edition.

http://www.magentocommerce.com/

Also decided to use ExtJs as user interface rendering engine.

http://www.extjs.com/

To work on server side objects without touching javascript code we decided to use PHP-Ext adapter.

http://php-ext.quimera-solutions.com/

Soon will drop about details. May be will publish Magento module as well.