I am using Zend_Validate_Db_NoRecordExists detailed in the link below to check if a record exists before inserting it.
I have no issues with the basic code and have got it working fine, what I need to do next is add a WHERE clause to exclude records where the field recordDelete = 1.
Zebd_Validate_Db_NoRecordExists
Here is a snippet of the code where I'm using this:
$validator = new Zend_Validate_Db_NoRecordExists($options);
$form->getElement('productSTOCKCODE')->addValidator($validator);
Thanks
$validate = new Zend_Validate_Db_RecordExists (array (
'table' => 'orders',
'field' => 'id',
'exclude' => 'recordDelete = 1'
));
$result = $validate->isValid ('000489FS1qT81XR4GWuV');
You could try creating you're own version of it and set the $_exclude member variable.
(Untested)
class My_Validate_Db_NoRecordExists
extends Zend_Validate_Db_NoRecordExists // notice what were extending here
{
protected $_exclude = array(
'field' => 'recordDelete',
'value' => 1
);
}
OR you could just pass the $exclude param along to the constructor wherever you're using it:
$options = array(
'table' => $yourTable,
'field' => $yourField,
'exclude' => array( // <- set exclude here
'field' => 'recordDelete',
'value' => 1
)
);
$dbValidator = new Zend_Validate_Db_NoRecordExists($options);
Related
I am trying to create an item with relationship field with multiple references like this.
$collection = new PodioCollection(array(
new PodioItem(array('item_id' => 425989858)),
new PodioItem(array('item_id' => 425987845))
));
$response = PodioItem::create("16748745", array('fields' => array(
"130415123" => "+13334445552",
"130415337" => $collection
)));
While creating item it shows error PodioBadRequestError: "Invalid value null (null): must be Range". I have only these two fields in this app.
I get the same error with single reference also.
$response = PodioItem::create("16748745", array('fields' => array(
"130415123" => "+13334445552",
"130415337" => array('item_id' => 425989858)
)));
Any help?
This one should work
$response = PodioItem::create("16748745", array('fields' => array(
"130415123" => "+13334445552",
"130415337" => array(425989858, 425987845)
)));
I've tested this for Ruby code and that works well :)
created_item = Podio::Item.create(app_id,
'fields' =>
{'title' => 'just for test',
'relationship' => [item_1_id, item_2_id] })
I want first and last record id form $dataprovider which is passed to gridview which i need to pass to this link.
array(
'name' => 'msg',
'value' => 'CHtml::link(substr(strip_tags($data->msg),0,30)." .....",Yii::app()->createUrl("Mail/view",array("id"=>$data->primaryKey,"flag"=>"inbox","tab"=>'.$tab.',"category"=>'.$category.')))',
'type' => 'raw',
'header' => 'Message',
),
Declare two attributes in your controller.
public $first=null;
public $last=null;
Define a function in controller to render your link
public function renderMailViewLink($data,$row){
// you can return anything you want here. whether a link or whatever
// access $this->first->id , $this->last->id
return CHtml::link($data->anyAttribute,array('someRoute','id'=>$data->id,'first'=>$this->first->id))
}
CActiveDataProvider has a method getData(), which return array of all active records.
in actionIndex
$dataProvider = $model->search()
$data = $dataProvider->getData();
$this->first = reset($data );
$this->last = end($data);
And finally in your view
array(
'name' => 'msg',
'value' => array($this,'renderMailViewLink'),
'type' => 'raw',
'header' => 'Message',
),
Please note this code is not tested. But thats how it can be achieved
How can I set an application component property to be an array of objects from within the main.cpp config file?
in the components section of main.php config file we have a section:
'components' => array(
....
'company' => array(
'class' => 'application.components.Company',
'employees' => array(
'class' => 'application.components.Employee'
)
)
);
but the $company->employees property is just being set to 'application.components.Employee' ..
I would have expected it to be equal to array( new Employee) (ie an Employee object within an array) .
Any knowledge on this matter?
You'd need to use standard PHP notation here, not Yii's class specifier, since you're simply assigning a value to the component member var employees:
'company' => array(
'class' => 'application.components.Company',
'employees' => array(new Employee())
)
That said, why do this? Just initialize employee in the Company class's constructor or init method.
So it seems you want to use Yii's object initialization logic for your custom objects, right?
Something like this could help:
class Company extends CApplicatinoComponent
{
private $_employees = array();
public function setEmployees($value)
{
foreach($value as $config)
$this->_employees[] = Yii::createComponent($config);
}
public function getEmployees()
{
return $this->_employees;
}
}
Of course you should add some error checking. But now you can configure your employees like:
'company' => array(
'class' => 'Company',
'employees' => array(
array(
'class' => 'Employee',
'somePropertyOfEmployee' => 'bla',
),
array(
'class' => 'OtherEmployee',
'otherProperty' => 'bla',
),
),
),
Until now I have been binding input filters to the form in the module, in other words I have been creating elements in the form, adding input filters to the elements on the module side.
For example check this example
Right now im creating text field elements dynamically depending upon the requirements, like this in my form
//Form
public function addNamesTextFieldElement($names)
{
foreach($names as $name)
{
$nameTextField = new Element\Text($name->getName());
$nameTextField->setAttribute('type', "text");
$nameTextField->setLabel($name->getName());
$this->add($nameTextField );
}
}
What would be best approach where to add/attach input filters to such dynamically generated elements.
I probably wouldn't use this approach, but something like this would work, providing you have already assigned an InputFilter to the form:
public function addNamesTextFieldElement($names)
{
$factory = new InputFactory();
foreach($names as $name)
{
$nameTextField = new Element\Text($name->getName());
$nameTextField->setAttribute('type', "text");
$nameTextField->setLabel($name->getName());
$this->add($nameTextField );
$this->getInputFilter()->add(
$factory->createInput(array(
'name' => $name->getName(),
'required' => true,
'filters' => array(
array('name' => 'StripTags'),
array('name' => 'StringTrim'),
),
'validators' => array(
array(
'name' => 'StringLength',
'options' => array(
'encoding' => 'UTF-8',
'min' => 1,
'max' => 100,
),
),
),
))
);
}
}
I'm trying to use Lithiums list option with find() along with SQL's DISTINCT.
I should get an array populated with values, instead, I'm getting an empty array.
This does make sense since I'm passing in the distinct fields as one string instead of an array of elements but I don't know how else to use DISTINCT in Lithium.
Some direction would be greatly appreciated.
It may be valentines day but Lithium is not showing me too much love today :)
Model:
class ZipCodes extends \app\extensions\data\Model {
protected $_meta = array(
'key' => 'zip_code_id',
'title' => 'state_name'
);
protected $_schema = array(
'state_name' => array('type' => 'varchar'),
'StateFIPS' => array('type' => 'varchar')
//there are more fields in my table but I haven't defined the
//rest in my model
);
}
The add method in my controller
public function add()
{
$zipcodes = Zipcodes::find('list', array(
'fields' => array('DISTINCT state_name'),
'order' => 'state_name ASC',
'conditions' => array('state_name' => array('!=' => ''))
)
);
return compact('zipcodes');
}