
Class Controller_Category extends \Controller{
public function action_index($category) {
echo $category;
}
A Huzz wrote on Saturday 20th of August 2011:Something like this
Class Controller_Category extends \Controller{ public function action_index($category) { echo $category; }
http://domain.com/category/computer will echo computer
public function action_index($name = 'index'){
switch ($name){
case 'index':
$data = Model_Prod::find('all');
break;
case 'laptop':
$data = Model_Laptop::find('all');
break;
default:
echo "something wrong url Adress";
$data = Model_Prod::find('all');
break;
}
$this->response->body = View::factory('welcome/index')->set('data',$data);
}
Public function action_category($category,$subcategory,$product){
Echo $category;
Echo $subcategory;
Echo $product;
}
If you're still not sure then let me know I'll write some proper code for you.. am using my phone right now.
Also, read the manual controller section http://www.fuelphp.com/docs/general/controllers/base.html
Edited typo / code formatpublic function action_index($category = 'category', $subcategory = 'null', $product-name-ID = 'null')
{
if(isset($category))
{
if(isset($subcategory))
{
if(isset($product-name-ID))
{
$data = Model_$product-name-ID::find('all');
}else{
$data = Model_$subcategory::find('all');
}
}else{
$data = Model_$category::find('all');
}
}else{
//redirect to home page
}
}
CREATE TABLE `laptops` ( `id` int(11) NOT NULL AUTO_INCREMENT, `subject` varchar(45) CHARACTER SET latin1 NOT NULL, `price` varchar(45) CHARACTER SET latin1 NOT NULL, `photo` varchar(45) CHARACTER SET latin1 NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=9 DEFAULT CHARSET=utf8;
Dmitry Barko wrote on Tuesday 23rd of August 2011:CREATE TABLE `laptops` ( `id` int(11) NOT NULL AUTO_INCREMENT, `subject` varchar(45) CHARACTER SET latin1 NOT NULL, `price` varchar(45) CHARACTER SET latin1 NOT NULL, `photo` varchar(45) CHARACTER SET latin1 NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=9 DEFAULT CHARSET=utf8;
-- -- Table structure for table `categories` -- CREATE TABLE IF NOT EXISTS `categories` ( `id` int(4) NOT NULL AUTO_INCREMENT, `parent_id` int(4) NOT NULL, `name` varchar(100) NOT NULL, `seo_name` varchar(100) NOT NULL, `description` varchar(250) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=5 ; -- -- Dumping data for table `categories` -- INSERT INTO `categories` (`id`, `parent_id`, `name`, `seo_name`, `description`) VALUES (1, 0, 'Computer', 'Computer', 'Computers'), (2, 1, 'Laptop', 'Laptop', 'Laptop computers'), (3, 1, 'Desktop', 'Desktop', 'Desktop computers'), (4, 0, 'Software', 'Software', 'Softwares'); -- -------------------------------------------------------- -- -- Table structure for table `products` -- CREATE TABLE IF NOT EXISTS `products` ( `id` int(4) NOT NULL AUTO_INCREMENT, `cat_id` int(4) NOT NULL, `name` varchar(150) NOT NULL, `seo_name` varchar(150) NOT NULL, `description` text NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ; -- -- Dumping data for table `products` -- INSERT INTO `products` (`id`, `cat_id`, `name`, `seo_name`, `description`) VALUES (1, 2, 'HP Laptop', 'HP-Laptop', 'Dual Core processor\r\n2GB RAM\r\n2TB Hard Disk\r\nFloppy Disk\r\nUSB Drive'), (2, 2, 'Dell Laptop', 'Dell-Laptop', 'Dual Core processor\r\n2GB RAM\r\n2TB Hard Disk\r\nFloppy Disk\r\nUSB Drive');
It looks like you're new here. If you want to get involved, click one of these buttons!