本文整理汇总了PHP中Model_Category::find方法的典型用法代码示例。如果您正苦于以下问题:PHP Model_Category::find方法的具体用法?PHP Model_Category::find怎么用?PHP Model_Category::find使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Model_Category
的用法示例。
在下文中一共展示了Model_Category::find方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: show
protected function show($slug = false)
{
if (isset($sorting)) {
Model_Category::$sorting = $sorting;
}
if ($category = Model_Category::get_by_slug($slug)) {
// TODO delete this
srand($category->id);
$items = null;
$parent_category = null;
if ($category->parent_id == 0) {
$view_file = 'category';
// Categories
$items = Model_Category::find(array('where' => array('parent_id' => $category->id, 'status' => 1), 'order_by' => array('sort' => 'asc')));
} else {
$view_file = 'subcategory';
// Products
$items = $category->products;
$parent_category = Model_Category::find_one_by_id($category->parent_id);
}
\Helper::sorting($items);
// Reset to empty array if there are no result found by query
if (is_null($items)) {
$items = array();
}
// Initiate pagination
$pagination = \Hybrid\Pagination::make(array('total_items' => count($items), 'per_page' => \Input::get('per_page', 15), 'uri_segment' => null));
// Remove unwanted items, and show only required ones
$items = array_slice($items, $pagination->offset, $pagination->per_page);
\Theme::instance()->set_partial('content', $this->view_dir . $view_file)->set('category', $category, false)->set('parent_category', $parent_category, false)->set('items', $items, false)->set('pagination', $pagination, false);
} else {
throw new \HttpNotFoundException();
}
}
示例2: action_index
public function action_index($orderField = null)
{
if (is_null($orderField)) {
$orderField = 'name';
}
$categories_db = Model_Category::find('all', ['order_by' => ['name']]);
$categories[0] = "-- ALL --";
foreach ($categories_db as $category) {
$categories[$category->id] = $category->name;
}
$category_id = Input::get('category_id');
if (!is_null($category_id)) {
Session::set('displayCategory', $category_id);
if (strcmp($category_id, "0") == 0) {
$qualifiers = ['order_by' => [$orderField]];
} else {
$qualifiers = ['order_by' => [$orderField], 'where' => array(['category_id', Session::get('displayCategory')])];
}
} else {
$category_id = Session::get('displayCategory');
if (!isset($category_id)) {
$qualifiers = ['order_by' => [$orderField]];
} elseif (strcmp($category_id, "0") == 0) {
$qualifiers = ['order_by' => [$orderField]];
} else {
$qualifiers = ['order_by' => [$orderField], 'where' => array(['category_id', Session::get('displayCategory')])];
}
}
$products = Model_Product::find('all', $qualifiers);
$data = ['products' => $products, 'categories' => $categories, 'category_id' => $category_id];
return Response::forge(View::forge('home/index.tpl', $data));
}
示例3: before
/**
* set common data to template
*
* @author Luvina
* @access public
*
* @return void
*/
public function before()
{
parent::before();
$aryMenuList = Model_Category::find('all');
$this->template->menu = $aryMenuList;
$this->template->base_url = Config::get('base_url');
}
示例4: show
protected function show($slug = false)
{
if (isset($sorting)) {
Model_Category::$sorting = $sorting;
}
if ($category = Model_Category::get_by_slug($slug)) {
// TODO delete this
srand($category->id);
$items = null;
$parent_category = null;
if ($category->parent_id == 0) {
$view_file = 'category';
// Categories
$items = Model_Category::find(array('where' => array('parent_id' => $category->id, 'status' => 1), 'order_by' => array('sort' => 'asc')));
if (!$items) {
$view_file = 'subcategory';
$items = $category->products;
}
} else {
$view_file = 'subcategory';
// Products
$items = $category->products;
// echo '<pre>';
// print_r($items);
// echo '</pre>';
$parent_category = Model_Category::find_one_by_id($category->parent_id);
}
\Helper::sorting($items);
// Reset to empty array if there are no result found by query
if (is_null($items)) {
$items = array();
}
// Initiate pagination
$pagination = \Hybrid\Pagination::make(array('total_items' => count($items), 'per_page' => \Input::get('per_page', 15), 'uri_segment' => null));
// Remove unwanted items, and show only required ones
$items = array_slice($items, $pagination->offset, $pagination->per_page);
$category_parents = false;
if ($parent_category) {
$parents = array();
if ($category_parents_id = Model_Category::find_parents($category->parent_id, $parents, true)) {
$category_parents = Model_Category::find(array('where' => array(array('id', 'in', $category_parents_id))));
}
}
$stock_options = \Config::load('stock-option.db');
\Theme::instance()->set_partial('content', $this->view_dir . $view_file)->set('category', $category, false)->set('parent_category', $parent_category, false)->set('items', $items, false)->set('category_parents', $category_parents, false)->set('pagination', $pagination, false)->set('manage_stock', $stock_options['manage_stock'], false)->set('hide_out_of_stock', $stock_options['hide_out_of_stock'], false);
\View::set_global('title', $category->seo->meta_title ?: $category->title);
\View::set_global('meta_description', $category->seo->meta_description ?: '');
\View::set_global('meta_keywords', $category->seo->meta_keywords ?: '');
$robots = array('meta_robots_index' => $category->seo->meta_robots_index == 1 ? 'index' : 'noindex', 'meta_robots_follow' => $category->seo->meta_robots_follow == 1 ? 'follow' : 'nofollow');
\View::set_global('robots', $robots);
\View::set_global('canonical', $category->seo->canonical_links);
\View::set_global('h1_tag', $category->seo->h1_tag);
if ($category->seo->redirect_301) {
\Response::redirect($category->seo->redirect_301);
}
} else {
throw new \HttpNotFoundException();
}
}
示例5: get_id_by_parent_id
public static function get_id_by_parent_id($parent_category_id)
{
$data = array();
$categories = Model_Category::find('all', array('where' => array(array('parent_category_id', '=', $parent_category_id))));
foreach ($categories as $category) {
$data[] = $category->id;
}
return $data;
}
示例6: action_delete
public function action_delete($id = null)
{
if ($category = Model_Category::find($id)) {
$category->delete();
Session::set_flash('success', e('Deleted category #' . $id));
} else {
Session::set_flash('error', e('Could not delete category #' . $id));
}
Response::redirect('admin/category');
}
示例7: newAction
public function newAction()
{
$param['category'] = $this->_getParam('category');
$app = Model_Category::find($param['category']);
if ($app) {
throw new Exception("Category '" . $param['category'] . "' already exist.");
}
$c = new Model_Category();
$c->newCategory($param);
echo json_encode(array('success' => true));
}
示例8: action_delete
public function action_delete($id = null)
{
$category = Model_Category::find($id);
if ($category->delete()) {
// Delete cache
\Cache::delete('sidebar');
\Messages::success(__('backend.category.deleted'));
} else {
\Messages::error(__('error'));
}
\Response::redirect_back(\Router::get('admin_category'));
}
示例9: set_form_fields
public static function set_form_fields($form, $instance = null)
{
// Call parent for create the fieldset and set default value
parent::set_form_fields($form, $instance);
// Add null value for parent categories.
$form->field('parent_id')->set_options('null', 'None');
$categories = Model_Category::find('all', array('where' => array(array('parent_id', null))));
// Set categories
foreach ($categories as $category) {
$form->field('parent_id')->set_options($category->id, $category->name);
}
}
示例10: action_delete
/**
* Действие для удаления категории
*
* @param integer $id
*/
public function action_delete($id = null)
{
is_null($id) and Response::redirect('admin/categories');
$category = \Model_Category::find($id, array('related' => 'articles'));
if (!empty($category) and empty($category->articles)) {
$category->delete();
\Session::set_flash('success', 'Категория успешно удалена');
} else {
\Session::set_flash('error', 'Невозможно удалить категорию. Скорее всего существуют статьи, принадлежащие к ней.');
}
\Response::redirect('admin/categories');
}
示例11: set_form_fields
public static function set_form_fields($form, $instance = null)
{
// Call parent for create the fieldset and set default value
parent::set_form_fields($form, $instance);
// Set authors
foreach (\Model_User::find('all') as $user) {
$form->field('user_id')->set_options($user->id, $user->username);
}
// Set categories
foreach (Model_Category::find('all') as $category) {
$form->field('category_id')->set_options($category->id, $category->name);
}
}
示例12: action_add
public function action_add($id = null)
{
$this->data['isUpdate'] = $isUpdate = $id !== null ? true : false;
// Prepare form fieldset
$form = \Fieldset::forge('post_form', array('form_attributes' => array('class' => 'form-horizontal')));
$form->add_model('Model_Post');
$form->add('add', '', array('type' => 'submit', 'value' => $isUpdate ? __('backend.edit') : __('backend.add'), 'class' => 'btn btn-primary'));
// Get or create the post
if ($isUpdate) {
$this->data['post'] = $post = \Model_Post::find($id);
$this->dataGlobal['pageTitle'] = __('backend.post.edit');
} else {
$this->data['post'] = $post = \Model_Post::forge();
$this->dataGlobal['pageTitle'] = __('backend.post.add');
}
$form->populate($post);
// If POST submit
if (\Input::post('add')) {
$form->validation()->run();
if (!$form->validation()->error()) {
// Populate the post
$post->from_array(array('name' => $form->validated('name'), 'slug' => $form->validated('slug') != '' ? \Inflector::friendly_title($form->validated('slug')) : \Inflector::friendly_title($form->validated('name')), 'category_id' => $form->validated('category_id'), 'user_id' => $form->validated('user_id'), 'content' => $form->validated('content')));
if ($post->save()) {
// Delete cache
\Cache::delete('sidebar');
// Category Post count update
foreach (\Model_Category::find('all') as $category) {
$category->post_count = count($category->posts);
$category->save();
}
if ($isUpdate) {
\Messages::success(__('backend.post.edited'));
} else {
\Messages::success(__('backend.post.added'));
}
\Response::redirect_back(\Router::get('admin_post'));
} else {
\Messages::error(__('error'));
}
} else {
// Output validation errors
foreach ($form->validation()->error() as $error) {
\Messages::error($error);
}
}
}
$form->repopulate();
$this->data['form'] = $form;
$this->theme->set_partial('content', 'backend/post/add')->set($this->data, null, false);
}
示例13: get_sidebar
/**
* Get the sidebar view (HMVC Only)
*/
public function get_sidebar()
{
if (\Request::is_hmvc()) {
// Get sidebar in cache
try {
$sidebar = \Cache::get('sidebar');
} catch (\CacheNotFoundException $e) {
// If Cache doesn't exist, get data and cache the view
$this->data['categories'] = \Model_Category::find('all');
$this->data['lastPosts'] = \Model_Post::query()->order_by('created_at', 'DESC')->limit(5)->get();
$sidebar = $this->theme->view('frontend/post/sidebar', $this->data);
\Cache::set('sidebar', $sidebar);
}
return $sidebar;
}
}
示例14: action_index
/**
* Index page
*
* @access public
* @param $slug
*/
public function action_index($slug = false, $my_products = null)
{
$category_parents = false;
if ($my_products == 1) {
Model_Product::$filter_by_pricing_group = 'assigned';
} else {
Model_Product::$filter_by_pricing_group = 'not_assigned';
}
if ($product = Model_Product::get_by_slug($slug)) {
// Find main category
if (!empty($product->categories)) {
$parents = array();
if ($category_parents_id = Model_Category::find_parents(key($product->categories), $parents, true)) {
$category_parents = Model_Category::find(array('where' => array(array('id', 'in', $category_parents_id))));
}
}
\Theme::instance()->set_partial('content', $this->view_dir . 'product')->set('product', $product, false)->set('category_parents', $category_parents, false)->set('product_data', $product->data, false);
} else {
throw new \HttpNotFoundException();
}
}
示例15: post_create
public function post_create()
{
$val = Validation::forge();
$val->add_callable('MyRules');
$val->add_field('category_name', Lang::get('label.category_name'), 'required|max_length[255]');
$val->add_field('id', Lang::get('label.category'), 'trim|valid_numeric|valid_category');
$val->add_field('parent_category_id', Lang::get('label.parent_category'), 'trim|valid_numeric|valid_category');
if ($val->run()) {
DB::start_transaction();
$category_id = $val->validated('id');
$parent_category_id = (int) $val->validated('parent_category_id');
$category_props = array('category_name' => Model_Service_Util::mb_trim($val->validated('category_name')), 'parent_category_id' => $parent_category_id, 'level' => !empty($parent_category_id) ? Model_Category::find($parent_category_id)->level + 1 : 1);
$create_id = !empty($category_id) ? Model_Base_Category::update($category_id, $category_props) : Model_Base_Category::insert($category_props);
if ($create_id) {
$type = !empty($category_id) ? 'update' : 'new';
$category_id = !empty($category_id) ? $category_id : $create_id;
$photo_props = array('type' => $type, 'category_id' => $category_id);
if ($type === 'new' || Input::file('category_photo')) {
$upload = Model_Service_Upload::run('category', $photo_props);
}
if (empty($upload['error'])) {
DB::commit_transaction();
$this->data['category'] = array('type' => $type, 'id' => $category_id, 'parent_category_id' => $parent_category_id, 'category_name' => $val->validated('category_name'), 'category_name_display' => Model_Base_Category::get_parent($category_id), 'category_photo_display' => empty($upload['photo_name']) ?: $upload['photo_name'], 'no_image' => _PATH_NO_IMAGE_);
$this->data['success'] = true;
$this->data['msg'] = Lang::get($this->controller . '.' . $this->action . '.success');
} else {
DB::rollback_transaction();
$this->data['msg'] = $upload['error'];
}
} else {
DB::rollback_transaction();
$this->data['msg'] = Lang::get($this->controller . '.' . $this->action . '.error');
}
} else {
$this->data['errors'] = $val->error_message();
}
return $this->response($this->data);
}