当前位置: 首页>>代码示例>>PHP>>正文


PHP CategoryModel::model方法代码示例

本文整理汇总了PHP中CategoryModel::model方法的典型用法代码示例。如果您正苦于以下问题:PHP CategoryModel::model方法的具体用法?PHP CategoryModel::model怎么用?PHP CategoryModel::model使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CategoryModel的用法示例。


在下文中一共展示了CategoryModel::model方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: CategoryModel

<?php

$cate_name = $_GET['CateName'];
$style_id = $_GET['StyleId'];
if (trim($cate_name) !== "") {
    $connection = Yii::app()->db;
    //搜索 category 表中是否存在此次上送的 名字。 如果没有就插入记录。
    $categoryModel = new CategoryModel();
    $ret = CategoryModel::model()->find('name=:cate_name', array(':cate_name' => $cate_name));
    if (!isset($ret)) {
        $categoryModel->name = $cate_name;
        $categoryModel->create_time = time();
        $categoryModel->save();
    }
    //找到名字对应的_id。以便做插入 rel 关系表的时候用
    $sql = "select _id from tbl_category where name = :CateName";
    $command = $connection->createCommand($sql);
    $cate_id = $command->query(array(':CateName' => $cate_name))->readAll();
    if (isset($cate_id)) {
        //插入 tbl_style_category_rel 表
        $StyleCateRelModel = new StyleCateRelModel();
        $StyleCateRelModel->style_id = $style_id;
        $StyleCateRelModel->category_id = $cate_id[0]['_id'];
        $StyleCateRelModel->create_time = time();
        $StyleCateRelModel->save();
    }
}
$sql = "select B.name as cate_name\n\t\t\tfrom tbl_style_category_rel A\n\t\t\tinner join tbl_category B on B._id =  A.category_id\n\t\t\twhere A.style_id = :style_id order by B.name asc";
$command = $connection->createCommand($sql);
$cates = $command->query(array(':style_id' => $style_id))->readAll();
foreach ($cates as $cate) {
开发者ID:dalinhuang,项目名称:styleshop,代码行数:31,代码来源:AddCate.php

示例2: elseif

        if ($level == 3) {
            $topParentId = $_POST['top_parent_id'] = $categoryData['parent_id'];
        } elseif ($level == 2) {
            $topParentId = $_POST['top_parent_id'] = $categoryData['id'];
        } else {
            $topParentId = $_POST['top_parent_id'] = 0;
        }
        $_POST['level'] = $level;
    }
    if ($name == "" || $alias == "") {
        $createMessage = "请把分类信息填写完整!!";
    } else {
        $sql = 'SELECT * FROM `category` WHERE name="' . $name . '" or alias ="' . $alias . '"';
        $rs = $pdo->query($sql);
        $row = $rs->fetchAll();
        //取得所有记录
        $count = count($row);
        if ($count == 0) {
            // var_dump($_POST);
            $lastetId = CategoryModel::model()->create($_POST);
            if ($lastetId != FALSE) {
                $createMessage = "添加成功";
            } else {
                echo $sql;
                $createMessage = "添加失败";
            }
        } else {
            $createMessage = '分类名称重复 或者 别名重复!';
        }
    }
}
开发者ID:kwdwkiss,项目名称:trial,代码行数:31,代码来源:CategoryCreate.php

示例3: actionUpStyle

 public function actionUpStyle()
 {
     $connection = Yii::app()->db;
     $Cates = array();
     $Tags = array();
     $isSuc = false;
     $userId = $_REQUEST['id'];
     $picDesc = $_REQUEST['desc'];
     $category_name = $_REQUEST['category_name'];
     $tag_name = $_REQUEST['tag_name'];
     $categories = explode(",", $category_name);
     $tags = explode(",", $tag_name);
     //本地
     //$root = YiiBase::getPathOfAlias('webroot').Yii::app()->getBaseUrl();
     //服务器代码
     $root = YiiBase::getPathOfAlias('webroot');
     $folder = $root . '/images/images/styles/' . $userId . '/';
     $desFilePath;
     $tmpFilePath;
     $relPath = Yii::app()->getBaseUrl() . '/images/images/styles/' . $userId . '/';
     //echo ($folder);
     //exit();
     $this->mkDirIfNotExist($folder);
     if ($_FILES["file"]["type"] == "image/gif" || $_FILES["file"]["type"] == "image/jpeg" || $_FILES["file"]["type"] == "image/png" || $_FILES["file"]["type"] == "image/jpg" || $_FILES["file"]["type"] == "image/pjpeg") {
         if ($_FILES["file"]["error"] > 0) {
             $isSuc = false;
         } else {
             $tmpFilePath = $_FILES["file"]["tmp_name"];
             /*
             				$array = explode("/", $tmpFilePath); 
             				var_dump($array[ count($array) -1]);
             			    $tmpPath  = $tmpPath.$array[ count($array) -1];
             */
             $name = $this->getUploadImageFileName($_FILES["file"]["name"]);
             $desFilePath = $folder . $name;
             $desThumbPath = $folder . 'thumb/' . $name;
             $relPath = $relPath . $name;
             if (file_exists($desFilePath)) {
                 unlink($desFilePath);
                 //echo $_FILES["file"]["name"] . " already exists. ";
             } else {
                 move_uploaded_file($tmpFilePath, $desFilePath);
                 //生成缩略图
                 $im = null;
                 $imtp = null;
                 if ($_FILES["file"]["type"] == "image/gif") {
                     $im = imagecreatefromgif($desFilePath);
                     $imtp = 'gif';
                 } else {
                     if ($_FILES["file"]["type"] == "image/jpg" || $_FILES["file"]["type"] == "image/jpeg") {
                         $im = imagecreatefromjpeg($desFilePath);
                         $imtp = 'jpg';
                     } else {
                         if ($_FILES["file"]["type"] == "image/png") {
                             $im = imagecreatefrompng($desFilePath);
                             $imtp = 'png';
                         }
                     }
                 }
                 $this->mkDirIfNotExist($folder . 'thumb/');
                 CThumb::resizeImage($im, 100, 100, $desThumbPath, $imtp);
                 //------------生成缩略图
                 $isSuc = true;
             }
         }
     } else {
         $isSuc = false;
     }
     if ($isSuc) {
         $styleModel = new StyleModel();
         $tagModel = new TagModel();
         $categoryModel = new CategoryModel();
         $styleModel->image = $relPath;
         $styleModel->user_id = $userId;
         $styleModel->create_time = time();
         $styleModel->like_num = 0;
         $styleModel->recommand_val = 0;
         if (!$styleModel->save()) {
             echo "style saved fail!";
             return false;
         }
         foreach ($categories as $cate_name) {
             //搜索 category 表中是否存在此次上送的 名字。 如果没有就插入记录。
             $ret = CategoryModel::model()->find('name=:cate_name', array(':cate_name' => $cate_name));
             if (!isset($ret)) {
                 $categoryModel->name = $cate_name;
                 $categoryModel->create_time = time();
                 if (!$categoryModel->save()) {
                     echo "category zd fail!";
                 }
             }
             //找到名字对应的_id。以便做插入 rel 关系表的时候用
             $sql = "select _id from tbl_category where name = :CateName";
             $command = $connection->createCommand($sql);
             $tmp = $command->query(array(':CateName' => $cate_name))->readAll();
             array_push($Cates, array('cate_id' => $tmp[0]["_id"]));
         }
         foreach ($tags as $tag_name) {
             //搜索 tag 表中是否存在此次上送的 名字。 如果没有就插入记录。
             $ret = TagModel::model()->find('name=:tag_name', array(':tag_name' => $tag_name));
//.........这里部分代码省略.........
开发者ID:dalinhuang,项目名称:styleshop,代码行数:101,代码来源:ApiController.php

示例4: array

$error = array();
$updateMessage = '';
//批量修改
if ($dopost == 'mut_edit') {
    $idArr = $_POST["cid"];
    $totalExec = 0;
    foreach ($idArr as $id) {
        $alias = isset($_POST["alias"][$id]) ? $_POST["alias"][$id] : '';
        $sort = isset($_POST["sort"][$id]) ? $_POST["sort"][$id] : '';
        $sql = 'SELECT * FROM `category` WHERE `alias`="' . $alias . '" AND `id`<>"' . $id . '"';
        $rs = $pdo->query($sql);
        $row = $rs->fetchAll();
        //取得所有记录
        if (count($row) == 0) {
            $row = array('sort' => $sort, 'alias' => $alias);
            $result = CategoryModel::model()->update(array('id' => $id), $row);
            $totalExec += $result;
            $totalExec += $result;
        } else {
            $error[] = $title . '【名称重复】!';
        }
    }
    if ($totalExec <= 0) {
        echo $sql;
    }
    $updateMessage = "更新" . $totalExec . "条数据";
}
//删除单个数据
$delflag = $_GET["delflag"];
if ($delflag == 1) {
    $id = $_GET["id"];
开发者ID:kwdwkiss,项目名称:trial,代码行数:31,代码来源:CategoryManage.php

示例5: loadModel

 /**
  * Returns the data model based on the primary key given in the GET variable.
  * If the data model is not found, an HTTP exception will be raised.
  * @param integer the ID of the model to be loaded
  */
 public function loadModel($id)
 {
     $model = CategoryModel::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }
开发者ID:44n,项目名称:myEYii,代码行数:13,代码来源:CategoryController.php

示例6: getModelById

 public static function getModelById($id)
 {
     return CategoryModel::model()->findByPk($id);
 }
开发者ID:romeo14,项目名称:pow,代码行数:4,代码来源:ModelApi.php


注:本文中的CategoryModel::model方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。