本文整理汇总了PHP中CakeText::truncate方法的典型用法代码示例。如果您正苦于以下问题:PHP CakeText::truncate方法的具体用法?PHP CakeText::truncate怎么用?PHP CakeText::truncate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CakeText
的用法示例。
在下文中一共展示了CakeText::truncate方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: set
/**
* Sets the views meta data, if available
*
* @param array $data
* @return void
*/
public function set($data = array())
{
$Model = $this->__controller->{$this->__controller->modelClass};
// assign the meta title variable, starting with data assigned
// directly to MetaData, falling back next to the Model displayField
// variable before falling again to the Model displayName variable
if (!empty($data['MetaData']['title'])) {
$metaTitle = $data['MetaData']['title'];
} elseif (!empty($data[$Model->alias][$Model->displayField])) {
$metaTitle = $data[$Model->alias][$Model->displayField];
} else {
$metaTitle = Inflector::pluralize($data[$Model->alias][$Model->displayName]);
}
if (!empty($metaTitle)) {
$this->Controller->set(compact('metaTitle'));
}
// assign the meta description variable, starting with data
// assigned directly to MetaData, falling back to content
// and then body fields from within the supplied data
if (!empty($data['MetaData']['description'])) {
$metaDescription = $data['MetaData']['description'];
} elseif (!empty($data[$Model->alias]['body'])) {
// truncate the content variable to a max of 160 characters
// ref: https://moz.com/learn/seo/meta-description
$metaDescription = CakeText::truncate($data['MetaData']['description'], 160, array('html' => false));
} elseif (!empty($data[$Model->alias]['content'])) {
// truncate the content variable to a max of 160 characters
// ref: https://moz.com/learn/seo/meta-description
$metaDescription = CakeText::truncate($data[$Model->alias]['content'], 160, array('html' => false));
}
if (!empty($metaDescription)) {
$this->Controller->set(compact('metaDescription'));
}
return;
}