I am beginner in Yii Framework.I have created the _form.php with Yii widget CActiveForm.I have made the Checkbox list for week of days.I have serialized checkbox values on actioncreate and save into database table.Actually problem is that When i calling the actionupdate then my checked values are not showing that i have insert on actioncreate.actioncreate and actionupdate using the same form _form.php.
I have written my code below
actioncreate
public function actionCreate()
{
$model=new CustomerAccounts;
if(isset($_POST['CustomerAccounts']))
{
$model->attributes=$_POST['CustomerAccounts'];
$model->DateCreated = date('Y-m-d H:i:s');
$model->DeliveryDay = serialize($_POST['CustomerAccounts']['DeliveryDay']);
if($model->save()) {
Yii::app()->user->setFlash('success', 'Customer Account create successfully.');
$this->redirect(array('admin'));
} else {
Yii::app()->user->setFlash('danger','An error occurred. Please try again.');
}
}
$this->render('create',array(
'model'=>$model,
));
}
actionupdate
public function actionUpdate($id)
{
$model=$this->loadModel($id);
if(isset($_POST['CustomerAccounts']))
{
$model->attributes=$_POST['CustomerAccounts'];
$model->DeliveryDay = serialize($_POST['CustomerAccounts']['DeliveryDay']);
$model->DateCreated = date('Y-m-d H:i:s');
if($model->save()) {
Yii::app()->user->setFlash('success', 'Customer Account update successfully.');
$this->redirect(array('admin'));
} else {
Yii::app()->user->setFlash('danger','An error occurred. Please try again.');
}
}
$this->render('update',array(
'model'=>$model,
));
}
_form.php
<?php $form=$this->beginWidget('CActiveForm', array(
'id'=>'customer-accounts-form',
'enableAjaxValidation'=>false,
<div class="row">
<div class="col-lg-12" style="padding-left: 34px;">
<?php echo $form->labelEx($model, 'DeliveryDay'); ?>
<?php echo $form->error($model, 'DeliveryDay'); ?>
<div id="checkbox" style="padding-left: 90px;">
<?php
$htmlOptions = array('template' => '<tr><td >{input}</td> <td> {label}</td> </tr', 'multiple' => true, 'checked' => 'checked');
echo $form->checkBoxList($model, 'DeliveryDay', Yii::app()->params['WeekDays'], $htmlOptions);
?>
</div></div></div>
<?php $this->endWidget(); ?>
Here my model
class CustomerAccounts extends CActiveRecord
{
public function tableName()
{
return 'customer_accounts';
}
public function rules()
{
return array(
array('DeliveryDay, Status, CustomerID, Employee_ID, PaymentModeID', 'required'),
array('CustomerID, Employee_ID, PaymentModeID, PcBottle, Bottle6Ltr, Bottle1500Ml, Bottle500Ml, TabStand, Pump, DispensirStatus, PCBottlesQuantity, PCBottleSecurity, DispensirQuantity, DispensirSerialNo, DispensirSecurity, TotalAmount, Status', 'numerical', 'integerOnly'=>true),
array('DateJoin', 'length', 'max'=>250),
array('Description', 'safe'),
array('CustomerAccountID, CustomerID, Employee_ID, PaymentModeID, DateJoin, PcBottle, Bottle6Ltr, Bottle1500Ml, Bottle500Ml, TabStand, Pump, DispensirStatus, PCBottlesQuantity, PCBottleSecurity, DispensirQuantity, DispensirSerialNo, DispensirSecurity, TotalAmount, DeliveryDay, Description, Status, DateCreated', 'safe', 'on'=>'search'),
);
}
public function relations()
{
return array(
'customer' => array(self::BELONGS_TO, 'Customer', 'CustomerID'),
'employee' => array(self::BELONGS_TO, 'Employee', 'Employee_ID'),
'paymentMode' => array(self::BELONGS_TO, 'PaymentMods', 'PaymentModeID'),
);
}
public function attributeLabels()
{
return array(
'CustomerAccountID' => 'Customer Account',
'CustomerID' => 'Customer',
//'Employee_ID' => 'Employee',
'Employee_ID' => 'Sale Person',
'PaymentModeID' => 'Payment Mode',
'DateJoin' => 'Date Join',
'PcBottle' => 'Pc Bottle',
'Bottle6Ltr' => 'Bottle6 Ltr',
'Bottle1500Ml' => 'Bottle1500 Ml',
'Bottle500Ml' => 'Bottle500 Ml',
'TabStand' => 'Tab Stand',
'Pump' => 'Pump',
'DispensirStatus' => 'Dispensir Status',
'PCBottlesQuantity' => 'Pcbottles Quantity',
'PCBottleSecurity' => 'Pcbottle Security',
'DispensirQuantity' => 'Dispensir Quantity',
'DispensirSerialNo' => 'Dispensir Serial No',
'DispensirSecurity' => 'Dispensir Security',
'TotalAmount' => 'Total Amount',
'DeliveryDay' => 'Delivery Day',
'Description' => 'Description',
'Status' => 'Status',
'DateCreated' => 'Date Created',
);
}
public function search()
{
$criteria=new CDbCriteria;
$criteria->compare('CustomerAccountID',$this->CustomerAccountID);
$criteria->compare('CustomerID',$this->CustomerID);
$criteria->compare('Employee_ID',$this->Employee_ID);
$criteria->compare('PaymentModeID',$this->PaymentModeID);
$criteria->compare('DateJoin',$this->DateJoin,true);
$criteria->compare('PcBottle',$this->PcBottle);
$criteria->compare('Bottle6Ltr',$this->Bottle6Ltr);
$criteria->compare('Bottle1500Ml',$this->Bottle1500Ml);
$criteria->compare('Bottle500Ml',$this->Bottle500Ml);
$criteria->compare('TabStand',$this->TabStand);
$criteria->compare('Pump',$this->Pump);
$criteria->compare('DispensirStatus',$this->DispensirStatus);
$criteria->compare('PCBottlesQuantity',$this->PCBottlesQuantity);
$criteria->compare('PCBottleSecurity',$this->PCBottleSecurity);
$criteria->compare('DispensirQuantity',$this->DispensirQuantity);
$criteria->compare('DispensirSerialNo',$this->DispensirSerialNo);
$criteria->compare('DispensirSecurity',$this->DispensirSecurity);
$criteria->compare('TotalAmount',$this->TotalAmount);
$criteria->compare('DeliveryDay',$this->DeliveryDay,true);
$criteria->compare('Description',$this->Description,true);
$criteria->compare('Status',$this->Status);
$criteria->compare('DateCreated',$this->DateCreated,true);
return new CActiveDataProvider($this, array(
'criteria'=>$criteria,
));
}
public static function model($className=__CLASS__)
{
return parent::model($className);
}
}
Would anyone Can tell me when i call the actionupdate How the checked values will be shows from database table ?
You have to unserialized checkbox values afterFind() function in your model file (i.e. models/CustomerAccounts.php) as follows:
public function afterFind() {
$this->DeliveryDay = unserialize($this->DeliveryDay);
parent::afterFind();
}
Related
hi i am using yii framework but when i left image field blank while update , it will get oldfile from model like
$model = $this->loadModel($id);
$oldImage = $model->image;
but while updating it throw error that image type not valid , but old image type valid is save like my old image name is test.jpg .
But when i remove model rule
array('image', 'file', 'types' => 'jpg, gif, png', 'message' => 'Please choose correct file format','on'=>'insert'),
update work fine i am unable to understand where the problem is
Below is code of my actionUpdate
public function actionUpdate($id) {
$model = $this->loadModel($id);
$oldImage = $model->image;
if (isset($_POST['Product'])) {
$model->attributes = $_POST['Product'];
$rnd = rand(0, 9999); // generate random number between 0-9999
$uploadedFile = CUploadedFile::getInstance($model, 'image');
if (!empty($uploadedFile)) {
$fileName = "{$rnd}" . time() . "{$uploadedFile}"; // random number + file name
$model->image = $fileName;
$uploadedFile->saveAs(Yii::app()->basePath . '/../images/product/' . $fileName);
unlink(Yii::app()->basePath . "/../images/product/" . $oldImage);
} else {
$model->image = $oldImage;
}
if ($model->save())
$this->redirect(array('view', 'id' => $model->id));
else {
CVarDumper::dump($model->getErrors(), 10, 1);
exit;
}
}
$this->render('update', array(
'model' => $model,
));
}
and below is my _form view page
<div class="form">
<?php
$form = $this->beginWidget('CActiveForm', array(
'id' => 'product-form',
'enableAjaxValidation' => false,
'htmlOptions' => array('enctype' => 'multipart/form-data'),
));
?>
<p class="note">Fields with <span class="required">*</span> are required.</p>
<?php echo $form->errorSummary($model); ?>
<div class="row">
<?php echo $form->labelEx($model, 'title'); ?>
<?php echo $form->textField($model, 'title', array('size' => 60, 'maxlength' => 256)); ?>
<?php echo $form->error($model, 'title'); ?>
</div>
<div class="row">
<?php
echo $form->labelEx($model, 'slug');
echo $form->textField($model, 'slug', array('size' => 60, 'maxlength' => 256));
echo $form->error($model, 'slug');
?>
</div>
<div class="row">
<?php
echo $form->labelEx($model, 'image');
echo CHtml::activeFileField($model, 'image');
echo $form->error($model, 'image');
?>
</div>
<?php if ($model->isNewRecord != '1') {
?>
<div class="row">
<?php echo CHtml::image(Yii::app()->request->baseUrl . '/images/product/' . $model->image, "image", array("width" => 200)); ?>
</div>
<?php } ?>
<div class="row">
<?php
echo $form->labelEx($model, 'status');
echo $form->dropDownList($model, 'status', array('active' => 'Active', 'inactive' => 'InActive'), array('empty' => 'Select Status'));
echo $form->error($model, 'status');
?>
</div>
<div class="row buttons">
<?php echo CHtml::submitButton($model->isNewRecord ? 'Create' : 'Save'); ?>
</div>
<?php $this->endWidget(); ?>
and MOdel is below
<?php
class Product extends CActiveRecord {
/**
* #return string the associated database table name
*/
public function tableName() {
return 'products';
}
/**
* #return array validation rules for model attributes.
*/
public function rules() {
// NOTE: you should only define rules for those attributes that
// will receive user inputs.
return array(
array('title, image, status', 'required'),
// array('image', 'file', 'types' => 'jpg, gif, png', 'message' => 'Please choose correct file format'),
array('created_by, modified_by', 'numerical', 'integerOnly' => true),
array('title', 'length', 'max' => 256),
array('slug', 'length', 'max' => 256),
array('status', 'length', 'max' => 8),
array('image, created_at, modified_at', 'safe'),
// The following rule is used by search().
// #todo Please remove those attributes that should not be searched.
array('id, title, slug, image, status, created_at, created_by, modified_at, modified_by', 'safe', 'on' => 'search'),
);
}
/**
* #return array relational rules.
*/
public function relations() {
// NOTE: you may need to adjust the relation name and the related
// class name for the relations automatically generated below.
return array(
'productitems' => array(self::HAS_MANY, 'Productitems', 'proid'),
);
}
/**
* #return array customized attribute labels (name=>label)
*/
public function attributeLabels() {
return array(
'id' => 'ID',
'title' => 'Title',
'slug' => 'Slug',
'image' => 'Image',
'status' => 'Status',
'created_at' => 'Created At',
'created_by' => 'Created By',
'modified_at' => 'Modified At',
'modified_by' => 'Modified By',
);
}
public function search() {
// #todo Please modify the following code to remove attributes that should not be searched.
$criteria = new CDbCriteria;
$criteria->compare('id', $this->id);
$criteria->compare('title', $this->title, true);
$criteria->compare('slug', $this->slug, true);
$criteria->compare('image', $this->image, true);
$criteria->compare('status', $this->status, true);
$criteria->compare('created_at', $this->created_at, true);
$criteria->compare('created_by', $this->created_by);
$criteria->compare('modified_at', $this->modified_at, true);
$criteria->compare('modified_by', $this->modified_by);
return new CActiveDataProvider($this, array(
'criteria' => $criteria,
));
}
public static function model($className = __CLASS__) {
return parent::model($className);
}
}
I am using YII Framework but when i update my information excluding image , it throw error that image type is not valid , even i have valid iamge type .
it throw error that
Please fix the following input errors:
Image cannot be blank.
Please choose correct file format
public function actionUpdate($id) {
$model = $this->loadModel($id);
$oldImage = $model->image;
if (isset($_POST['Product'])) {
$model->attributes = $_POST['Product'];
$rnd = rand(0, 9999); // generate random number between 0-9999
$uploadedFile = CUploadedFile::getInstance($model, 'image');
if (!empty($uploadedFile)) {
$fileName = "{$rnd}" . time() . "{$uploadedFile}"; // random number + file name
$model->image = $fileName;
$uploadedFile->saveAs(Yii::app()->basePath . '/../images/product/' . $fileName);
#unlink(Yii::app()->basePath . "\\..\\images\\product\\" . $oldImage);
} else {
$model->image = $oldImage;
}
if ($model->save())
$this->redirect(array('view', 'id' => $model->id));
}
$this->render('update', array(
'model' => $model,
));
}
and my _form file is below
<div class="form">
<?php
$form = $this->beginWidget('CActiveForm', array(
'id' => 'product-form',
'enableAjaxValidation' => false,
'htmlOptions' => array('enctype' => 'multipart/form-data'),
));
?>
<p class="note">Fields with <span class="required">*</span> are required.</p>
<?php echo $form->errorSummary($model); ?>
<div class="row">
<?php echo $form->labelEx($model, 'title'); ?>
<?php echo $form->textField($model, 'title', array('size' => 60, 'maxlength' => 256)); ?>
<?php echo $form->error($model, 'title'); ?>
</div>
<div class="row">
<?php
echo $form->labelEx($model, 'slug');
echo $form->textField($model, 'slug', array('size' => 60, 'maxlength' => 256));
echo $form->error($model, 'slug');
?>
</div>
<div class="row">
<?php
echo $form->labelEx($model, 'image');
echo CHtml::activeFileField($model, 'image');
echo $form->error($model, 'image');
?>
</div>
<?php if ($model->isNewRecord != '1') {
?>
<div class="row">
<?php echo CHtml::image(Yii::app()->request->baseUrl . '/images/product/' . $model->image, "image", array("width" => 200)); ?>
</div>
<?php } ?>
<div class="row">
<?php
echo $form->labelEx($model, 'status');
echo $form->dropDownList($model, 'status', array('active' => 'Active', 'inactive' => 'InActive'), array('empty' => 'Select Status'));
echo $form->error($model, 'status');
?>
</div>
<div class="row buttons">
<?php echo CHtml::submitButton($model->isNewRecord ? 'Create' : 'Save'); ?>
</div>
<?php $this->endWidget(); ?>
and my model is below
<?php
class Product extends CActiveRecord {
public function tableName() {
return 'products';
}
public function rules() {
// NOTE: you should only define rules for those attributes that
// will receive user inputs.
return array(
array('title, image, status', 'required'),
array('image', 'file', 'types' => 'jpg, gif, png', 'message' => 'Please choose correct file format'),
array('created_by, modified_by', 'numerical', 'integerOnly' => true),
array('title', 'length', 'max' => 256),
array('slug', 'length', 'max' => 256),
array('status', 'length', 'max' => 8),
array('image, created_at, modified_at', 'safe'),
// The following rule is used by search().
// #todo Please remove those attributes that should not be searched.
array('id, title, slug, image, status, created_at, created_by, modified_at, modified_by', 'safe', 'on' => 'search'),
);
}
/**
* #return array relational rules.
*/
public function relations() {
return array(
'productitems' => array(self::HAS_MANY, 'Productitems', 'proid'),
);
}
/**
* #return array customized attribute labels (name=>label)
*/
public function attributeLabels() {
return array(
'id' => 'ID',
'title' => 'Title',
'slug' => 'Slug',
'image' => 'Image',
'status' => 'Status',
'created_at' => 'Created At',
'created_by' => 'Created By',
'modified_at' => 'Modified At',
'modified_by' => 'Modified By',
);
}
/**
* Retrieves a list of models based on the current search/filter conditions.
*
* Typical usecase:
* - Initialize the model fields with values from filter form.
* - Execute this method to get CActiveDataProvider instance which will filter
* models according to data in model fields.
* - Pass data provider to CGridView, CListView or any similar widget.
*
* #return CActiveDataProvider the data provider that can return the models
* based on the search/filter conditions.
*/
public function search() {
// #todo Please modify the following code to remove attributes that should not be searched.
$criteria = new CDbCriteria;
$criteria->compare('id', $this->id);
$criteria->compare('title', $this->title, true);
$criteria->compare('slug', $this->slug, true);
$criteria->compare('image', $this->image, true);
$criteria->compare('status', $this->status, true);
$criteria->compare('created_at', $this->created_at, true);
$criteria->compare('created_by', $this->created_by);
$criteria->compare('modified_at', $this->modified_at, true);
$criteria->compare('modified_by', $this->modified_by);
return new CActiveDataProvider($this, array(
'criteria' => $criteria,
));
}
/**
* Returns the static model of the specified AR class.
* Please note that you should have this exact method in all your CActiveRecord descendants!
* #param string $className active record class name.
* #return Product the static model class
*/
public static function model($className = __CLASS__) {
return parent::model($className);
}
}
You are using a CFileValidator for the field image in your Product class, and you are restricting the formats that can be uploaded, as it is written in the following line:
array('image', 'file', 'types' => 'jpg, gif, png', 'message' => 'Please choose correct file format'),
The problem you are having is that CFileValidator does not allow file fields to be empty by default, so you have to explicitly set the allowEmpty attribute of the rule to true.
That said, your rule should be written as follows:
array('image', 'file', 'types' => 'jpg, gif, png', 'allowEmpty' => true, 'message' => 'Please choose correct file format'),
You can see more about Model Rules Validation in the following link:
http://www.yiiframework.com/wiki/56/#hh12
Hope it helps.
I have Settings controller like
public function actionIndex()
{
$model = new SettingsForm;
if(isset($_POST['SettingsForm'])) {
if($model->validate()) {
//
}
}
$this->render('index', array('model' => $model));
}
and in settings view:
<?php
$form = $this->beginWidget(
'CActiveForm', array(
'id' => 'settings-form',
'enableClientValidation' => true,
'clientOptions' => array(
'validateOnSubmit' => true,
),
));
?>
<div class="form-group">
<?php echo $form->labelEx($model, 'meta_keywords'); ?>
<?php echo $form->textField($model, 'meta_keywords', array('class' => 'form-control', 'value' => Yii::app()->config->get('meta_keywords'), 'placeholder' => 'Ключевые слова и фразы через запятую')); ?>
<?php echo $form->error($model, 'meta_keywords', array('class' => 'text-danger')); ?>
</div>
<div class="form-group">
<?php echo $form->labelEx($model, 'main_page'); ?>
<?php echo $form->dropDownList($model, 'main_page', $model->getPages()); ?>
<?php echo $form->error($model, 'main_page', array('class' => 'text-danger')); ?>
</div>
function getPages in SettingsForm model:
public function getPages() {
return array(
0 => 'Nothing'
);
}
This code returns error:
Property "SettingsForm.main_page" is not defined.
But all previos elements Yii created successfully and don't return any error =\
In your SettingsForm model is main_page defined in the rules method? i.e.
public function rules()
{
// NOTE: you should only define rules for those attributes that
// will receive user inputs.
return array(
array( ... 'main_page', ...),
...
);
}
/**
* #return array validation rules for model attributes.
*/
public function rules()
{
// NOTE: you should only define rules for those attributes that
// will receive user inputs.
return array(
array('site_name, charset, meta_description, meta_keywords', 'required'),
array('main_page', 'boolean')
);
}
Updated
class SettingsForm extends CFormModel
Still do it. Look at here and here (rus).
public function rules()
{
return array(
array('site_name, charset, meta_description, meta_keywords', 'required'),
array('main_page', 'boolean'),
array('site_name, charset, meta_description, meta_keywords, main_page', 'safe'),
);
}
Pfffff....
I just forgot call variable in model $main_page...
class SettingsForm extends CFormModel
{
public $site_name;
public $charset;
public $meta_description;
public $meta_keywords;
public $main_page;
..
}
I have a problem that i can`t get throught.
I am trying to display information from relational table like this:
$dataProvider = PartnerSite::model()->with('siteCommercials')->findAll("user_id=" . Yii::app()->user->id);
$this->render('index', array(
'dataProvider' => $dataProvider,
'allMoney' => 1
));
But in my view i am seeing that error:
Relation "siteCommercials" is not defined in active record class "PartnerSite".
But the fact is that my model have relation:
public function relations() {
return array(
'goesFromSites' => array(self::HAS_MANY, 'GoesFromSite', 'site_id'),
'user' => array(self::BELONGS_TO, 'User', 'user_id'),
'siteCommercials' => array(self::HAS_MANY, 'SiteCommercial', 'site_id'),
);
}
So my question is. Is there is something wrong? I can't get it... In only one that model is a lot of problems... BeforeSave() doesn't work and relations work not well. User relation is working just fine.
Full listing of "model":
<?php
abstract class BasePartnerSite extends GxActiveRecord {
public $siteCommercials = "oke";
public static function model($className=__CLASS__) {
return parent::model($className);
}
public function tableName() {
return '{{partner_site}}';
}
public static function label($n = 1) {
return Yii::t('app', 'PartnerSite|PartnerSites', $n);
}
public static function representingColumn() {
return 'site_name';
}
public function rules() {
return array(
array('site_name', 'required'),
array('user_id', 'numerical', 'integerOnly'=>true),
array('site_name', 'length', 'max'=>255),
array('id, site_name, user_id', 'safe', 'on'=>'search'),
);
}
public function relations() {
return array(
'goesFromSites' => array(self::HAS_MANY, 'GoesFromSite', 'site_id'),
'user' => array(self::BELONGS_TO, 'User', 'user_id'),
'siteCommercials' => array(self::HAS_MANY, 'SiteCommercial', 'site_id'),
);
}
public function pivotModels() {
return array(
);
}
public function attributeLabels() {
return array(
'id' => Yii::t('app', 'ID'),
'site_name' => Yii::t('app', 'Site Name'),
'user_id' => null,
'goesFromSites' => null,
'user' => null,
'siteCommercials' => null,
);
}
public function search() {
$criteria = new CDbCriteria;
$criteria->compare('id', $this->id);
$criteria->compare('site_name', $this->site_name, true);
$criteria->compare('user_id', $this->user_id);
return new CActiveDataProvider($this, array(
'criteria' => $criteria,
));
}
}
Your class is BasePartnerSite. In this class you define relation siteCommercials.
Your error message: "Relation "siteCommercials" is not defined in active record class "PartnerSite".
So then shouldn't your code be?
$dataProvider = BasePartnerSite::model()->with('siteCommercials')->findAll("user_id=" . Yii::app()->user->id);
So I've inherited a Yii application, I'm trying to get a piece this application to work that does a basic CRUD for management of Scientific factsheets. We're using Yii with Giix
This is the error:
"PHP Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 16 bytes) in /var/www/idtools.org/www/yii/framework/db/ar/CActiveRecord.php on line 58"
The update action is giving us the problems. The update looks like this in the controller:
public function actionUpdate($id) {
$model = $this->loadModel($id, 'Factsheet');
if (isset($_POST['Factsheet'])) {
$model->setAttributes($_POST['Factsheet']);
if ($model->save()) {
$this->redirect(array('view', 'id' => $model->factsheetid));
}
}
$this->render('update', array(
'model' => $model,
));
}
The view looks like:
$this->breadcrumbs = array(
$model->label(2) => array('index'),
GxHtml::valueEx($model) => array('view', 'id' => GxActiveRecord::extractPkValue($model, true)),
Yii::t('app', 'Update'),
);
$this->menu = array(
array('label' => Yii::t('app', 'List') . ' ' . $model->label(2), 'url'=>array('index')),
array('label' => Yii::t('app', 'Create') . ' ' . $model->label(), 'url'=>array('create')),
array('label' => Yii::t('app', 'View') . ' ' . $model->label(), 'url'=>array('view', 'id' => GxActiveRecord::extractPkValue($model, true))),
array('label' => Yii::t('app', 'Manage') . ' ' . $model->label(2), 'url'=>array('admin')),
);
?>
<h1><?php echo Yii::t('app', 'Update') . ' ' . GxHtml::encode($model->label()) . ' ' . GxHtml::encode(GxHtml::valueEx($model)); ?></h1>
<?php
$this->renderPartial('_form', array(
'model' => $model));
?>
The model (as generated by Giix) looks like:
Yii::import('application.models._base.BaseFactsheet');
class Factsheet extends BaseFactsheet
{
public static function model($className=__CLASS__) {
return parent::model($className);
}
}
the model extends the base:
abstract class BaseFactsheet extends GxActiveRecord {
public static function model($className=__CLASS__) {
return parent::model($className);
}
public function tableName() {
return 'factsheet';
}
public static function label($n = 1) {
return Yii::t('app', 'Factsheet|Factsheets', $n);
}
public static function representingColumn() {
return 'name';
}
public function rules() {
return array(
array('name, toolid', 'required'),
array('weight', 'numerical', 'integerOnly'=>true),
array('name, toolid', 'length', 'max'=>255),
array('inputdate', 'safe'),
array('weight, inputdate', 'default', 'setOnEmpty' => true, 'value' => null),
array('factsheetid, name, toolid, weight, inputdate', 'safe', 'on'=>'search'),
);
}
public function relations() {
return array(
'tool' => array(self::BELONGS_TO, 'Tool', 'toolid'),
'factsheetcontents' => array(self::HAS_MANY, 'Factsheetcontent', 'factsheetid'),
'factsheetimages' => array(self::HAS_MANY, 'Factsheetimages', 'factsheetid'),
);
}
public function pivotModels() {
return array(
);
}
public function attributeLabels() {
return array(
'factsheetid' => Yii::t('app', 'Factsheetid'),
'name' => Yii::t('app', 'Name'),
'toolid' => null,
'weight' => Yii::t('app', 'Weight'),
'inputdate' => Yii::t('app', 'Inputdate'),
'tool' => null,
'factsheetcontents' => null,
'factsheetimages' => null,
);
}
public function search() {
$criteria = new CDbCriteria;
$criteria->compare('factsheetid', $this->factsheetid);
$criteria->compare('name', $this->name, true);
$criteria->compare('toolid', $this->toolid);
$criteria->compare('weight', $this->weight);
$criteria->compare('inputdate', $this->inputdate, true);
return new CActiveDataProvider($this, array(
'criteria' => $criteria,
));
}
}
Any idea how to fix my issue? I've given PHP all of my systems memory (memory_init(-1)) and just gotten heap dump errors. I need help, please tell me where to look as I am totally new to Yii.
You generally get that error as part of your _form partial file. I've often run into it when GxHtml is generating a dropdown menu.
GiiX isn't that efficient at properly pulling all the models out of the database and grabbing the appropriate key / name for your drop-downs. So it's often better to specify the fields you want to retrieve manually.
If you post your _form code (or at least the relevant portions), we can point out the line.