ws17
Новичок
Здравствуйте.
Версия коханы последняя.
В категории есть подкатегории, вид их такой.
сайт.ru/category/view/1
сайт.ru/category/view/2
сайт.ru/category/view/3
как убрать, /category/view/
а id категории 1-2-3, изменить на название категории, допустим название категории кирпичи, как сделать так.
сайт.ru/kirpichi
А так же в этих категориях есть товар.
сайт.ru/category/product/7417
как убрать это /category/product/, а сделать что бы там было название категории в которой товар, допустим сайт.ru/kirpichi/7417
а так же как заменить id товара на правильное название, допустим это 7417 заменить на bigkirpich
и получить такой вариант: сайт.ru/kirpichi/bigkirpich
На данный момент небольшая часть чпу уже сделана, категория выводиться, название.
сайт.ru/category/view/kirpichi
но хотелось бы убрать category/view/
/application/classes/controller/index
category.php
Добавлено:
но это я так понимаю не все, помогали делать, и сделана таблица в бд в категориях ali
Версия коханы последняя.
В категории есть подкатегории, вид их такой.
сайт.ru/category/view/1
сайт.ru/category/view/2
сайт.ru/category/view/3
как убрать, /category/view/
а id категории 1-2-3, изменить на название категории, допустим название категории кирпичи, как сделать так.
сайт.ru/kirpichi
А так же в этих категориях есть товар.
сайт.ru/category/product/7417
как убрать это /category/product/, а сделать что бы там было название категории в которой товар, допустим сайт.ru/kirpichi/7417
а так же как заменить id товара на правильное название, допустим это 7417 заменить на bigkirpich
и получить такой вариант: сайт.ru/kirpichi/bigkirpich
На данный момент небольшая часть чпу уже сделана, категория выводиться, название.
сайт.ru/category/view/kirpichi
но хотелось бы убрать category/view/
/application/classes/controller/index
category.php
Добавлено:
Код:
public function action_view()
{
$alias = $this->request->param("id");
$cat = ORM::factory('category')->where('alias','=',$alias)->or_where('id','=',$alias)->find();
$id = $cat->id;
$settings = ORM::factory('setting')->find();
if($cat->products>1){
if(empty($cat->id)){
$this->request->redirect();
}
$products = DB::query(Database::SELECT, "SELECT image,prname,price,products.id,full_name FROM `products` LEFT JOIN `images` ON products.image_id = images.id WHERE status = 0 AND category = $id ORDER BY products.price ASC")->execute()->as_array();
$content = View::factory('index/main/v_cat_ro')
->bind('cat',$cat)
->bind('settings',$settings)
->bind('products',$products);
}else{
$cats = ORM::factory('category')->where('parent_id','=',$id)->find_all();
$content = View::factory('index/main/v_cats')
->bind('cats',$cats)
->bind('settings',$settings)
->bind('id', $id);
}
$this->template->site_name = $cat->cat_title.' '. $settings->title;
$this->template->description = $cat->cat_des.' '. $settings->description;
$this->template->keywords = $cat->cat_keys.' '. $settings->keywords;
$this->template->content = $content;
}
public function action_views()
{
$alias = $this->request->param("id");
$cat = ORM::factory('category')->where('alias','=',$alias)->or_where('id','=',$alias)->find();
$id = $cat->id;
$settings = ORM::factory('setting')->find();
if($cat->parent_id != 0){
$cats = ORM::factory('category')->where('parent_id','=',$cat->parent_id)->find_all();
}
else
{
$cats = array();
}
$products = DB::query(
Database::SELECT, "SELECT image,prname,price,products.id FROM
`products` LEFT JOIN `images` ON products.image_id = images.id
WHERE status = 1 AND category = $id
ORDER BY products.sorts ASC")->execute()->as_array('id');
if(is_array($products))
{
foreach($products as $product){
$pid = $product['id'];
$options = DB::query(Database::SELECT, "SELECT * FROM `optionprice` WHERE product_id = $pid ORDER BY `id` ASC")->execute()->as_array();
$products[$pid]['option_price'] = $options;
}
}
$content = View::factory('index/main/v_subcats')
->bind('cat',$cat)
->bind('settings',$settings)
->bind('cats',$cats)
->bind('products',$products)
->bind('id', $id);
$this->template->site_name = $cat->cat_title.' '. $settings->title;
$this->template->description = $cat->cat_des.' '. $settings->description;
$this->template->keywords = $cat->cat_keys.' '. $settings->keywords;
$this->template->content = $content;
}
public function action_product()
{
$id = (int)$this->request->param("id");
$product = ORM::factory('product')->where('id','=',$id)->find();
$image = ORM::factory('image')->where('id','=',$product->image_id)->find();
$images = ORM::factory('image')->where('product_id','=',$product->id)->find_all();
$settings = ORM::factory('setting')->find();
$options = DB::query(Database::SELECT, "SELECT * FROM `optionprice` WHERE product_id = $id ORDER BY `id` ASC")->execute()->as_array();
$content = View::factory('index/main/view_product')
->bind('image',$image)
->bind('images',$images)
->bind('options',$options)
->bind('product',$product);
$this->template->site_name = $product->prtitle.' '. $settings->title;
$this->template->description = $product->prdes.' '. $settings->description;
$this->template->keywords = $product->prkeys.' '. $settings->keywords;
$this->template->content = $content;
}
public function action_test()
{
$id = (int) $this->request->param('id');
$cat = ORM::factory('category', $id);
$cat->delete();
}
public function action_test1()
{
$id = (int) $this->request->param('id');
$products = ORM::factory('product', $id);
$products->delete();
}
}
Последнее редактирование: