add multiple
data for a model. I have Business and Bizimage model. From a single
form, I have to add an single entry for Business and multiple entry
for Bizimage. When there is no image,it is working fine. But when i
want to add image for every Bizimage entry, it is giving prob(sql
error).
Here is my model:
Business:
class Business extends AppModel {
var $name = 'Business';
var $primaryKey = 'business_id';
var $displayField = 'name';
var $actsAs= array(
'Image'=>array(
'fields'=>array(
'company_img'=>array(
'thumbnail' => array
('prefix'=>'thumb',
'create'=>true,
'width'=>'123',
'height'=>'110',
'aspect'=>true,
'allow_enlarge'=>true,
),
'resize'=>null,
)
)
)
);
var $hasMany = array(
'Bizimage' => array(
'className' => 'Bizimage',
'foreignKey' => 'business_id',
)
);
}
Bizimage:
class Bizimage extends AppModel {
var $name = 'Bizimage';
var $primaryKey = 'bizimage_id';
var $displayField = 'name';
var $belongsTo = array(
'Business' =>
array('className' => 'Business',
'foreignKey' => 'bizimage_id'
),
);
var $actsAs= array(
'biz_img'=>array(
'thumbnail' => array
('prefix'=>'thumb',
'create'=>true,
'width'=>'123',
'height'=>'110',
'aspect'=>true,
'allow_enlarge'=>true,
),
'resize'=>null,
)
);
}
In view:
echo $form->create('Business', array( 'action' => 'add' ,
'type'=>'file') );
echo $form->input( 'name', array( 'div' => false, 'label' => false,
'class' => 'textbox1Long' ) );
echo $form->input( 'address', array( 'div' => false, 'label' => false,
'class' => 'textbox1Long' ) );
echo $form->input( 'phone_no', array( 'div' => false, 'label' =>
false, 'class' => 'textbox1Long' ) );
echo $form->input('Bizimage.0.name', array( 'div' => false, 'label' =>
false, 'class' => 'textbox1Long' ));
echo $form->file('Bizimage.0.biz_img');
echo $form->input('Bizimage.1.name', array( 'div' => false, 'label' =>
false, 'class' => 'textbox1Long' ));
echo $form->file('Bizimage.1.biz_img');
In controller:
$this->Business->create();
if ($this->Business->saveAll($this->data))
$this->redirect('../businesses/index/msg:Successfully added.');
It is giving error:
SQL Error: 1054: Unknown column 'Array' in 'field list' [CORE\cake
\libs
\model\datasources\dbo_source.php, line 525]
Query: INSERT INTO `bizimages` (`name`, `biz_img`, `business_id`,
`modified`, `created`) VALUES ('test 21', Array, 50, '2009-11-20
06:36:40', '2009-11-20 06:36:40')
Query: INSERT INTO `bizimages` (`name`, `biz_img`, `business_id`,
`modified`, `created`) VALUES ('test 22', Array, 50, '2009-11-20
06:36:40', '2009-11-20 06:36:40')
What is solution for this prob?
--
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com.
To unsubscribe from this group, send email to cake-php+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en.
No comments:
Post a Comment