當前位置: 首頁>>代碼示例>>PHP>>正文


PHP CakeText::truncate方法代碼示例

本文整理匯總了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;
 }
開發者ID:mrstu84,項目名稱:metadata,代碼行數:41,代碼來源:MetaComponent.php


注:本文中的CakeText::truncate方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。