Create New row using bootstrap widgets TbSelect2 - yii

Hello I am using bootstrap.widgets.TbSelect2 in Yii.
You can see this link to check my form.
https://www.diigo.com/item/p/qoaqepdzbsbbaqeqdzbcbrsdpa/bc91ebd999371bef68737b8320afed91
How to add the data in TbSelect2?
thank you.

its so simple , just generate an array for this
$this->widget('bootstrap.widgets.TbSelect2', array(
'asDropDownList' => true,
'name' => 'status',
'data' => array( // свои значения для option
'active' => 'Active',
'pending' => 'Pending',
'invited' => 'Invited',
'deleted' => 'Deleted'
),
)
);

Related

how to keep selected filter option dropdown selected after CGridView update in Yii 1.1.14?

One of the filter options in my CGridView in Yii 1.1.14, has this
array(
'header' => 'Status',
'name' => 'status',
'filter' => CHtml::dropDownList('MyModel[status]','status', array(
'' => '',
'0' => 'Approved',
'1' => 'Pending',
'2' => 'Rejected'
)),
'type' => 'raw',
'value' => 'MyHelper::model()->getStatus($data->status)',
'htmlOptions' => array('width' => '8%')
),
My problem is, whenever I select one from the dropdown filter, the CGridView updates the result which is right, but then the selected option from the dropdown disappears, I mean it doesn't remain selected. How to keep it selected?
You have to pass selected value to dropDownList. like below
CHtml::dropDownList('MyModel[status]', MyModel->status, array(
'' => '',
'0' => 'Approved',
'1' => 'Pending',
'2' => 'Rejected'
)),
I have given default Approved status. i.e second parameter of dropDownList function.
Whenever your gridview reloads, firstly the call goes to you controller's action there you must have declared you model's variable/object, so in your controller's action you can set this variable to your model like this :
$myModel->status = $_GET['status'];
and when call returns to your view, there you can check for the value, that is set to that 'status' variable.

how to save id of one table to another table in codeigniter?

i want to save id of one table to another table how should i write the model and controller.
For example : I have a database like this
tbl1: (id,content,time,date,category)
tbl2: (id,tbl1_id,category_detail)
$tbl1Data = array(
'id' => '',
'content' => 'Hi, content will be here',
'time' => date("H:i:s"),
'date' => date("Y-m-d"),
'category' => 'Electronics'
);
$this->db->insert('tbl1',$postData);
$recordId $this->db->insert_id();
$tbl2Data = array(
'id' => '',
'tbl1_id' => $recordId,
'category_detail' => "alskjdflkajsdlk falsjdflka lsdkfj as",
);
$this->db->insert('tbl1',$postData);

How to fitch the result from Yii active recorde query with relations and scopes

This is my code
$vacanciesObjects = Vacancies::model()->status('approved')->visibility('Visible')->removed(0)->archived(0)->findAll(
array(
'with'=>array(
'job'=>array(
//'select' => 'title',
'scopes'=>array(
'offline' => array(0),
),
'with' => array(
'employer'=>array(
'scopes'=>array(
'status_id_not_in' => array('Blocked'),
),
),
),
),
), 'limit'=> 5, 'condition' => 'number_of_views > 0', 'order' => 'number_of_views DESC',
)
);
I can get the values for the columns in table vacancies but not from other table, any help regarding this ?
sorry I'm newbie on Yii
I figure out this problem by this
$vacanciesObject->job['title']

like OR operator in Cakephp

I am new to cakephp and I want to add or, and, and like to my existing query.
I want to make a condition like this
WHERE 'Message.user_id = Contact.user_id' AND 'Message.mobileNo LIKE'=>"%Contact.mobileNo" OR LIKE'=>"%Contact.homeNo" OR LIKE'=>"%Contact.workNo"
My query is
$this->bindModel(array(
'belongsTo' => array(
'Contact' => array(
'className' => 'Contact',
'foreignKey' => false,
'conditions' => array(
'Message.user_id = Contact.user_id',
'Message.mobileNo = Contact.mobileNo'
),
'type' => 'inner'
)
)
), false);
$this->find('all', array('conditions' => array(),
'fields' => array('DISTINCT mobileNo')));
you can use like below in your existing query.
$this->find('all', array(
'conditions' => array(
'OR' => array(
array(
"Message.mobileNo LIKE" => "%Contact.mobileNo",
),
array(
"Message.mobileNo LIKE" => "%Contact.homeNo",
),
array(
"Message.mobileNo LIKE" => "%Contact.workNo",
)
)
),
'fields' => array('DISTINCT mobileNo')
));
And you can also refer Detail Document for simple search with like
you can use: for "like"
$this->Post->find("all",array('condition'=>array('Author
LIKE'=>"ad%")));
above query will give You the data from table posts where author name starts with "ad".
for "OR"
$this->Post->find("all",array('condition'=>array("OR"=>array('Author
LIKE'=>"ad%",'Author LIKE'=>"bo%"))));
above query will give You the data from table posts where author name starts with "ad" OR "bo"
This blog post can b useful to u as well!

How to do this query condition in cakephp?

How can I make this query the CakePHP way?
SELECT *
FROM uploaded_sales us, sales s
WHERE us.item_id = s.audience_id
The column item_id of uploaded_sales table is not its primary key.
The column audience_id of sales table is not its primary key too.
I tried this one on my model, I'm not getting any errors but it still returns sales as empty:
$reports = $this->find('all',
array(
'joins' => array(
array(
'table' => 'sales',
'alias' => 'Sale',
'type' => 'left',
'conditions' => array('Sale.audience_id' => 'UploadedSale.item_id')
)),
'conditions' => array(
'UploadedSale.month' => $month,
'UploadedSale.year' => $year,
'UploadedSale.company_id' => $company_id,
'UploadedSale.item_type' => $item_type
),
'fields' => $fields
));
return $reports;
Learn about using the Containable behavior in CakePHP:
http://book.cakephp.org/view/1323/Containable
It will make joins a helluva lot easier.