本文整理汇总了PHP中Tags::findFirst方法的典型用法代码示例。如果您正苦于以下问题:PHP Tags::findFirst方法的具体用法?PHP Tags::findFirst怎么用?PHP Tags::findFirst使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Tags
的用法示例。
在下文中一共展示了Tags::findFirst方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getTagByName
public function getTagByName($name)
{
$tag = Tags::findFirst(['conditions' => 'name = :name:', 'bind' => ['name' => $name]]);
if (null == $tag) {
$tag = new Tags();
$tag->name = $name;
$tag->save();
}
return $tag;
}
示例2: addTags
/**
* Adds tags to a post
*/
public function addTags($tags)
{
foreach ($tags as $t) {
$t = trim($t);
$tag = Tags::findFirst(array("tag = '{$t}'"));
if (!$tag) {
$tag = new Tags();
$tag->tag = $t;
$tag->save();
}
$postTag = PostTags::findFirst(array("conditions" => "posts_id = ?1 AND tags_id = ?2", "bind" => array(1 => $this->id, 2 => $tag->id)));
if (!$postTag) {
$postTag = new PostTags();
$postTag->posts_id = $this->id;
$postTag->tags_id = $tag->id;
$postTag->save();
}
unset($tag);
unset($postTag);
}
}
示例3: Users
$filter = new Phalcon\Filter();
$user = new Users();
$data = $request->getPost('tags', null, false);
$image = Images::findFirst("id = '" . $id . "'");
$tags = [];
/**
* Save each tag
* This is done by:
* 1) Getting/creating the tag
* 2) Creating an imageTag
* 3) Saving the imageTag
*/
foreach ($data as $tagRow) {
$name = $filter->sanitize($tagRow['name'], 'string');
//Get tag if it exists already
$tag = Tags::findFirst("name = '" . $name . "' AND category_id = '" . $tagRow['category_id'] . "'");
if (!$tag) {
$tag = new Tags();
}
$tag->name = $name;
$tag->category_id = $tagRow['category_id'];
//If the tag could not be saved, dump the error messages
if (!$tag->save()) {
echo 'could not save tag.';
var_dump($tagRow);
var_dump($tag->getMessages());
$app->response->setStatusCode('500');
$app->response->send();
}
$tag->refresh();
//Create an imageTag for each tag
示例4: getTag
/**
* @return Tags
*/
public function getTag()
{
return Tags::findFirst($this->tag_id);
}
示例5: tag
/**
* @return Tags
*/
public function tag()
{
return $this->make('tag', function () {
return Tags::findFirst($this->tag_id);
});
}
示例6: fetchWidgetData
public function fetchWidgetData($view, $block = '')
{
$widgetData = array();
$blockCfgKey = $block ? $view . '_' . $block : $view;
$blockCfg = $this->_siteConfig['blockCfg'][$blockCfgKey];
$blockNum = $this->_siteConfig['widgetCfg']['blockNum'];
switch ($view) {
case 'slider':
//理财故事
//理财故事
case 'btslider':
$widgetData[$block] = array('blockName' => $block, 'items' => $this->_siteConfig['slider'][$block]);
break;
case 'dailyword':
$dailyword['title'] = '天天词汇';
$dailyword['word'] = Tags::findFirst(array("conditions" => "is_cidian = ?1", "bind" => array(1 => 1)))->toArray();
$widgetData = $dailyword;
break;
case 'content':
switch ($block) {
case 'node':
$content = TreeData::findFirst($this->_params['nid'])->toArray();
$content['content'] = htmlspecialchars_decode($content['content']);
$widgetData[$block]['content'] = $content;
break;
case 'tag':
$content = Tags::findFirst($this->_params['tid'])->toArray();
$content['content'] = htmlspecialchars_decode($content['description']);
$content['title'] = $content['name'];
$widgetData[$block]['content'] = $content;
break;
case 'static':
$static_content = TreeStruct::findFirst(array("conditions" => "pid = ?1", "bind" => array(1 => $this->_params['nid']), 'order' => 'lft asc'));
$content = array();
if ($static_content) {
$content['title'] = $static_content->TreeData->title;
$content['content'] = htmlspecialchars_decode($static_content->TreeData->content);
}
$widgetData[$block]['blockName'] = $block;
$widgetData[$block]['content'] = $content;
break;
default:
break;
}
break;
case 'cidian':
$cidianCloudNum = $this->_siteConfig['widgetCfg']['cidianCloudNum'];
$tags = Tags::fetchCidiansCloud($cidianCloudNum);
$widgetData = $tags;
break;
case 'hangqing':
case 'lilv':
case 'tool':
break;
case 'taglist':
$taglist = array();
$itemPer = $this->_siteConfig['widgetCfg']['listItemPer'];
$start = ($this->_params['p'] - 1) * $itemPer;
if ($this->_params['tagPrefix']) {
$conditions = 'pinyinPrefix="' . $this->_params['tagPrefix'] . '" and is_cidian=1';
} else {
$conditions = 'is_cidian=1';
}
$taglist['items'] = Tags::find(array('conditions' => $conditions, 'order' => 'id desc', 'limit' => array('number' => $itemPer, 'offset' => $start)))->toArray();
$totalTags = Tags::count($conditions);
$params = array('total_rows' => $totalTags, 'now_page' => $this->_params['p'], 'list_rows' => $itemPer);
$pagerLib = new Pager($params);
$pager = $pagerLib->show(3);
$taglist['pager'] = $pager;
// echo '<pre>';print_r($taglist);echo '</pre>';
$widgetData = $taglist;
break;
case 'taglist_header':
$optRanges = array(97, 122);
$options = array();
$options[] = '0-9';
for ($i = $optRanges[0]; $i <= $optRanges[1]; $i++) {
$options[] = chr($i);
}
$widgetData = $options;
break;
case 'list':
switch ($block) {
case 'node':
$nodeLists = array();
$itemPer = $this->_siteConfig['widgetCfg']['listItemPer'];
$start = ($this->_params['p'] - 1) * $itemPer;
$temNodes = TreeStruct::find(array('conditions' => 'lft>?1 and rgt<?2 and type=:type:', 'bind' => array(1 => $this->_params['node']->lft, 2 => $this->_params['node']->rgt, 'type' => 'article'), 'limit' => array('number' => $itemPer, 'offset' => $start), 'order' => 'id desc'));
$nodes = array();
foreach ($temNodes as $key => $temNode) {
$treeData = $temNode->TreeData->toArray();
$nodes[$key] = $temNode->toArray();
$nodes[$key]['TreeData'] = $treeData;
}
$nodes = TreeStruct::addNodesAttr($nodes, array('menu' => true, 'menuLevel' => 1));
$totalNodes = TreeStruct::count(array('conditions' => 'lft>?1 and rgt<?2 and type=:type:', 'bind' => array(1 => $this->_params['node']->lft, 2 => $this->_params['node']->rgt, 'type' => 'article')));
$params = array('total_rows' => $totalNodes, 'now_page' => $this->_params['p'], 'list_rows' => $itemPer);
$pagerLib = new Pager($params);
$pager = $pagerLib->show(3);
$nodeLists['title'] = $this->_params['node']->TreeData->title;
//.........这里部分代码省略.........