本文整理汇总了PHP中CategoryModel::all方法的典型用法代码示例。如果您正苦于以下问题:PHP CategoryModel::all方法的具体用法?PHP CategoryModel::all怎么用?PHP CategoryModel::all使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CategoryModel
的用法示例。
在下文中一共展示了CategoryModel::all方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: searchCategories
static function searchCategories($query, $limit = 10)
{
// $query = mysql_real_escape_string($query);
$categoryObjects = CategoryModel::all(array('conditions' => 'categories_lang.name LIKE \'%' . $query . '%\'', "limit" => $limit, 'order' => '`order` ASC, `id` ASC', 'joins' => array('categories_lang'), 'group' => 'id'));
$categories = array();
foreach ($categoryObjects as $c) {
$cat = Activerecord::returnArrayWithLang($c);
$categories[] = $cat;
}
return $categories;
}
示例2: getCategoryId
/**
* will query the db and get all the categories, if the categoryName is not
* in the categories table, it will insert it,
* otherwise it will return the category id
*/
public static function getCategoryId($categoryName)
{
$categories = CategoryModel::all();
// find the category id
foreach ($categories as $cat) {
if ($categoryName == $cat['category_name']) {
return $cat['id'];
}
}
// category wasn't found, so we need to insert one
$query = 'INSERT INTO categories (category_name) VALUES (:category_name)';
$stmt = static::$dbc->prepare($query);
$stmt->bindValue(":category_name", $categoryName, PDO::PARAM_STR);
$stmt->execute();
return self::getCategoryId($categoryName);
}
示例3: pageController
function pageController()
{
$errors['count'] = 0;
$arrayCategoriesArray = CategoryModel::all();
foreach ($arrayCategoriesArray as $categoriesArray) {
$categorySelectionList[] = $categoriesArray['category_name'];
}
$imageSuccessMessage = "";
//if an image was submitted - validate it even before validating the rest of the form
if (isset($_FILES['fileToUpload']) && $_FILES['fileToUpload']['name'] != '') {
try {
$postImage = Input::getImage('fileToUpload');
//image was successfully uploaded
$imageSuccessMessage = "Image: " . basename($_FILES['fileToUpload']['name']) . " has been uploaded!";
//store image in the session
$_SESSION['image'] = $postImage;
} catch (Exception $e) {
$errors['image'] = 'Image: ' . $e->getMessage();
$errors['count']++;
}
}
//clicked on the upload image button without selecting a photo
if (isset($_FILES['fileToUpload']) && $_FILES['fileToUpload']['name'] == '') {
$errors['image'] = "Image: Select an image to upload!";
$errors['count']++;
}
//if the session['image'] is empty; then, no image was submitted
if (!isset($_SESSION['image'])) {
//no image was submitted - use placeholder image
$postImage = "http://placehold.it/350x300";
} else {
//an image has been submitted; use the image stored in the $_SESSION
$postImage = $_SESSION['image'];
}
//if there weren't any errors with the image; then, process then rest of the form
if ($errors['count'] == 0) {
$errors = processForm($postImage);
}
return array('categorySelectionList' => $categorySelectionList, 'errorMessages' => $errors, 'imageSuccessMessage' => $imageSuccessMessage);
}
示例4: fixCategoryOrderRecursive
function fixCategoryOrderRecursive($parent_id = null)
{
$parent_condition = $parent_id != null ? '`parent_id` = ' . $parent_id : '`parent_id` IS NULL';
$categories = CategoryModel::all(array('conditions' => $parent_condition, 'order' => '`order` ASC'));
$order = 0;
if ($categories != null) {
foreach ($categories as $c) {
$c->order = $order;
$c->save();
$order++;
$this->fixCategoryOrderRecursive($c->id);
}
}
}