$term = array(
'vid' => 1, // Voacabulary ID
'name' => $data[3], // Term Name
'parent' => 181, // (Optional) Term ID of a parent term
);
taxonomy_save_term($term);
How do I get the term id that was just added?
You can get term id by echo $term->tid
Thanks,
Snehal
Related
I have a MySQL database and a table within it. The mission is to set a method, which will receive 2 parameters(?user_id=...&action_id...) and search for records matching these two fields or one of them, if only one was set(?user_id=...), then paginate them and send them to the action view. I've just started to learn Phalcon a week ago, have done some research here and there, read the docs and still don't realize how i can do this.
What i've done so far:
public function searchAction()
{
$userID = $this->request->get("user_id", "int", 0);
$actionID = $this->request->get("action_id", "int", 0);
$currentPage = 1;
$currentPage = (int) $_GET["page"];
$parameters = array(
'user_id' => $userID,
'action_id' => $actionID
);
$o = History::find($parameters);
$paginator = new Paginator(array(
"data" => $o,
"limit" => 10,
"page" => $currentPage
));
$page = $paginator->getPaginate();
$this->view->setVar("page", $page);
}
Pagination is working somehow but the search is not, why?
First parameter in the method find() or findFirst() must be a string to set conditions to the query.
In your case, you can search like that:
$o = History::find('user_id = "'.$userID.'" AND action_id = "'.$action_id.'"');
But, if you want add more parameters, then you need to pass array and the first element must contain search conditions:
$o = History::find(array(
'user_id = "'.$userID.'" AND action_id = "'.$action_id.'"',
'limit' => 10,
'order' => 'user_id ASC'
));
Referring to official documentation http://docs.phalconphp.com/en/latest/reference/models.html#binding-parameters
$conditions = "user_id = ?1 AND action_id = ?2";
$parameters = array(1 => userID, 2 => $actionID);
$o = History::find(array(
$conditions,
"bind" => $parameters
));
Index of parameters array must match number of placeholder in conditions string.
I'm try to add custom option to product programmatically whyle add him to cart. I'm use:
$a_options = array(
'options' => array(
'label' => 'Glove Size',
'value' => $attr_value ,
)
);
$item->addOption(new Varien_Object(
array(
'product' => $item->getProduct(),
'code' => 'additional_options',
'value' => serialize($a_options)
)
));
$quote->addItem($item);
This is shows option for product in cart and during checkout process, but don't show option in order information.
I also tried:
$item->getProduct()->addCustomOption('additional_options', $attr_value );
Try to show them via attributes - didn't help.
$params = array('product' => '1919','qty' => 1,
'options' => array(
'glove_size' => $gloves_id,
),);
$cart->addProduct('1919', $params);
Magento version is 1.5
I haven't check that in 1.5 version but the below code will work in 1.7.2 version:
For viewing the custom options you need set options in order items.That can be done through by calling an event sales_convert_quote_item_to_order_item
<sales_convert_quote_item_to_order_item>
<observers>
<jrb_setcustomoption_observer>
<type>singleton</type>
<class>jrb_setcustomoption/observer</class>
<method>salesConvertQuoteItemToOrderItem</method>
</jrb_setcustomoption_observer>
</observers>
</sales_convert_quote_item_to_order_item>
Set the details options in your observer
public function salesConvertQuoteItemToOrderItem(Varien_Event_Observer $observer)
{
$quoteItem = $observer->getItem();
if ($additionalOptions = $quoteItem->getOptionByCode('additional_options')) {
$orderItem = $observer->getOrderItem();
$options = $orderItem->getProductOptions();
$options['additional_options'] = unserialize($additionalOptions->getValue());
$orderItem->setProductOptions($options);
}
}
For More details you can find in this article:
Magento - custom product option don't show in order
Thanks to Vinai
I have a problem with searching in Yii. I have two models: Teams and Workers. On website there is a page called 'Team Workers' where I want to display CGridView widget with searching that displays Workers from the team (team id is passed as a _GET parameter).
I did this in TeamsController:
public function actionWorkers($id)
{
$model = Teams::model()->findByPk($id);
$workers = Workers::model();
$workers->unsetAttributes();
if(isset($_GET['Workers']))
{
$_GET['Workers']['idTeam'] = $id;
$workers->attributes = $_GET['Workers'];
}
else {
$workers->attributes = array('idTeam' => $id);
}
$teamWorkers = $workers;
$this->render('workers', array(
'model' => $model,
'teamWorkers' => $teamWorkers
));
}
And in the view file:
<?php $this->widget('zii.widgets.grid.CGridView', array(
'id'=>'team-workers-grid',
'dataProvider'=>$teamWorkers->search(),
'filter' => $teamWorkers,
'columns'=>array(
'name',
'surname',
array(
'id' => 'idWorker',
'class' => 'CCheckBoxColumn',
'checked' => '$data->confirmer',
'selectableRows' => '2',
// 'headerTemplate' => '{item}'
)
),
)); ?>
I got the error:
CDbCommand nie zdołał wykonać instrukcji SQL: SQLSTATE[23000]: Integrity constraint
violation: 1052 Column 'idTeam' in where clause is ambiguous. The SQL statement
executed was: SELECT COUNT(DISTINCT `t`.`idWorker`) FROM `workers` `t` LEFT OUTER JOIN
`teams` `Team` ON (`t`.`idTeam`=`Team`.`idTeam`) WHERE ((idTeam=:ycp0) AND (Team.name
LIKE :ycp1))
When I dont set idTeam attribute - it works fine. It's pretty weird - at the regular CRUD admin page - idTeam attribute is passed and that works fine.
Hot to deal with it?
In Workers::search() you have something like
$criteria->compare('idTeam',$this->idTeam);
Change it to
$criteria->compare('t.idTeam',$this->idTeam);
i.e prefix sql attribute with t. if it is from current model or with relation name if from other table/model
Also instead of:
$workers->attributes = array('idTeam' => $id);
yould could keep it simpler with:
$workers->idTeam = $id;
You have defined the column idTeam in Team and Workers. By joining those tables you would have a duplicate ("ambiguous") column in the result. That's what the error message tells you.
To solve this you have to use an alias for one of the columns.
I need to programmatically set up a node reference field.
My module successfully creates a and associates a pair of 'CCK' fields to my nodes. One of these fields is a node_reference field. My code is a follows:
$field_ref_name = 'field_custom_reference';
$field = field_info_field($field_ref_name);
if (empty($field)) {
$field = array(
"field_name"=>$field_ref_name,
"label"=>"Custom Reference",
"type"=>"node_reference",
"cardinality"=>"1",
'locked' => TRUE,
);
field_create_field($field);
}
$instance = array(
"field_name"=>$field_ref_name,
"label"=>"Sequence Reference",
"type"=>"node_reference",
"widget"=>array(
"type"=>"node_reference_autocomplete"
),
"description" => "text describing purpose of this field",
);
$instance["entity_type"] = "node";
$instance["bundle"] = $type;
if( !in_array($type, $field['bundles']['node']) )
field_create_instance($instance);
Now, the code works but when I edit a node inputting a valid value into the node reference field and attempt to save, I get the following error:
...: this post can't be referenced.
I realized the reason for the error is because the node reference field settings does not have any selected nodes as "Content types that can be referenced".
How can I adjust my code to set referenceable content types?
The reference-able types is a field setting. So it should be put under a "settings" array in the field definition. Something like -
$field = array(
"field_name"=>$field_ref_name,
"label"=>"Custom Reference",
"type"=>"node_reference",
"cardinality"=>"1",
'locked' => TRUE,
'settings' => array(
'referenceable_types' => array('article'),
),
);
I am trying to integrate a grid to my PHP project, JQgrid looked so easy!!
When i Integrated I was only able to see the grid, not the data in the grid!
I have just change the db settings of the sample code to work with my DB.
Debug results:
When I debugged with firebug I am able to see the db rows in the consolde mode of firebug.
Here with also pasting the logs of jqGrid.log
It also throws a warning msg "Warning: date() [function.date]: It is not safe to rely on the system's timezone settings. You are required to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'America/New_York' for '-5.0/no DST' instead in C:\Users\Karthik\Desktop\apache\htdocs\php\jqGrid.php(1) : eval()'d code on line 1"
Both files resides in root directory. Some clues to troubleshoot
PHP Code"myfristgrid.php"
require_once 'jq-config.php';
// include the jqGrid Class
require_once "php/jqGrid.php";
require_once "php/jqGridPdo.php";
$conn = new PDO(DB_DSN,DB_USER,DB_PASSWORD);
$conn->query("SET NAMES utf8");
$grid = new jqGridRender($conn);
$grid->debug = true;
$grid->SelectCommand = 'SELECT * FROM question';
$grid->datatype = 'json';
$grid->setColModel();
$grid->setUrl('myfirstgrid.php');
$grid->setGridOptions(array(
"caption"=>"This is custom Caption",
"rowNum"=>10,
"sortname"=>"id",
"hoverrows"=>true,
"rowList"=>array(10,20,50),
));
$grid->setColProperty("id", array("label"=>"ID", "width"=>60));
// Enjoy
$grid->renderGrid('#grid','#pager',true, null, null, true,true);
$conn = null;
jqGrid.log
Executed 2 query(s) - 2011-01-26 22:50:28
Array
(
[0] => Array
(
[time] => 2011-01-26 22:50:28
[query] => SELECT COUNT(*) AS COUNT FROM question
[data] =>
[types] =>
[fields] =>
[primary] =>
[input] =>
)
[1] => Array
(
[time] => 2011-01-26 22:50:28
[query] => SELECT * FROM question ORDER BY id asc LIMIT 0, 10
[data] =>
[types] =>
[fields] =>
[primary] =>
[input] =>
)
)
You can't properly use setColProperty in the jqGrid.