Hello I have create one module it's name is "ads" & in that I have created 2 models it's name is given below
1) ads_categories.php
2) ads_subcategories.php
I have created tables for both in INNODB (and also set relationship between both table)
I can able to do list/add/edit/delete for Categories. But for SubCategories it's giving me below error
======================================================
URL : www.test.com/fuel/ads/subcategories/create
An Error Was Encountered
Unable to locate the model you have specified: ads_categories_model
======================================================
Here is my Directory structure,
=======================
fuel
|modules
|ads
|config
|controllers
|models
- ads_categories.php
- ads_subcategories.php
=======================
Here is my Code for both models
=========================
============ ads_categories.php ===================
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
class Ads_categories_model extends Base_module_model {
public $required = array('title');
function __construct()
{
parent::__construct('ads_categories');
}
}
============ ads_subcategories.php ===================
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
require_once(FUEL_PATH.'models/base_module_model.php');
class Ads_subcategories_model extends Base_module_model {
public $required = array('title','id_ads_categories');
public $foreign_keys = array('id_ads_categories' => 'ads_categories_model');
function __construct()
{
parent::__construct('ads_subcategories');
}
}
=====================================================
Here is my ads_fuel_modules.php file
============================
<?php
// included in the main config/MY_fuel_modules.php
$config['modules']['ads_categories'] = array(
'module_name' => 'Categories',
'module_uri' => 'ads/categories',
'model_name' => 'ads_categories_model',
'model_location' => 'ads',
'display_field' => 'title',
'preview_path' => 'ads/categories/{id}',
'permission' => 'ads/categories',
'instructions' => 'Manage Ad Categories',
'archivable' => TRUE,
'configuration' => array('ads' => 'ads'),
'nav_selected' => 'ads/categories',
'sanitize_input' => array('template','php')
);
$config['modules']['ads_subcategories'] = array(
'module_name' => 'Sub Categories',
'module_uri' => 'ads/subcategories',
'model_name' => 'ads_subcategories_model',
'model_location' => 'ads',
'display_field' => 'title',
'preview_path' => 'ads/subcategories/{id}',
'permission' => 'ads/subcategories',
'instructions' => 'Manage Ad Sub Categories',
'archivable' => TRUE,
'configuration' => array('ads' => 'ads'),
'nav_selected' => 'ads/subcategories',
'sanitize_input' => array('template','php')
);
Can you please tell me What's wrong here? why it didn't found the model of "ads_categories_model" ? or is there anything I am missing?
Thanks in advance.
Comments
ad_categories_model.php
ad_subcategories_model.php
ads_categories_model.php
ads_subcategories_model.php
public $foreign_keys = array('id_ads_categories' => array('ads' => 'ads_categories_model'));
Thanks a lot for helping..
one minor thing, by default in the form Label is coming like "Ads_categorie*"
I want to put custom lable like "Choose Category" then what change is required?
$field['my_field']['label'] = 'Choose Category';
I am really thankful of you
I have add 3rd level in same module..
it's like categories >> sub-categories >> products
So in products form I need 2 Select Option
1) Choose Category (* Required)
2) Choose Sub Category (Optional)
So in ads_products_model.php I have pasted below code for "Foriegn Key"
in below code, it gives me correct option value in select box for "Category"
But in Sub Category select option it is showing me "Ids" (Primary key of categories)
Instead of Sub category title.
public $foreign_keys = array('id_ads_categories' => array('ads' => 'ads_categories_model'), 'id_ads_subcategories' => array('ads' => 'ads_subcategories_model'));
My Product table Structure..
=====================
id --> int(10)
id_ads_categories --> smallint(6) [Foriegn Key]
id_ads_subcategories --> int(10) [Foriegn Key]
product_name --> varchar(255)
price --> int(10)
description --> text
published enum --> ('yes', 'no')
create_date --> datetime
modify_date --> datetime
NOTE : in sub cateogry option list it is showing list of "id_ads_categories" instead of "subcategory_title"
Is it possible to make dependent field? like when I choose some category option and then it should load only related subcategory in Subcategory option box.
You'll need to specify the javascript jqx Controller file or the simple javascript file in your modules ads/config/ads_fuel_modules.php
but can you please tell me about my 1st question, In select box option I am getting "id_ads_categories" in list, instead of "subcategories_title", Is there anything wrong mentioned in above foreign key code?
CREATE TABLE `ads_products` (
`id` int(10) unsigned NOT NULL auto_increment,
`id_ads_categories` smallint(5) unsigned NOT NULL default '0',
`id_ads_subcategories` int(10) unsigned NOT NULL default '0',
`product_name` varchar(255) NOT NULL,
`price` int(10) unsigned NOT NULL default '0',
`image` varchar(50) default NULL,
`description` text,
`published` enum('yes','no') NOT NULL default 'yes',
`create_date` datetime default NULL,
`modify_date` datetime default NULL,
PRIMARY KEY (`id`),
KEY `id_ads_categories` (`id_ads_categories`),
KEY `id_ads_subcategories` (`id_ads_subcategories`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
--
-- Constraints for dumped tables
--
--
-- Constraints for table `ads_products`
--
ALTER TABLE `ads_products`
ADD CONSTRAINT `ads_products_ibfk_2` FOREIGN KEY (`id_ads_subcategories`) REFERENCES `ads_subcategories` (`id`) ON DELETE CASCADE,
ADD CONSTRAINT `ads_products_ibfk_1` FOREIGN KEY (`id_ads_categories`) REFERENCES `ads_categories` (`id`) ON DELETE CASCADE;
============================
Code of ads_products_model.php
============================
<?php if (!defined('BASEPATH')) exit('No direct script access allowed'); require_once(FUEL_PATH.'models/base_module_model.php'); class Ads_products_model extends Base_module_model { public $required = array('id_ads_categories','product_name','price'); public $foreign_keys = array('id_ads_categories' => array('ads' => 'ads_categories_model'), 'id_ads_subcategories' => array('ads' => 'ads_subcategories_model')); function __construct() { parent::__construct('ads_products'); } }
Is there anything else you require?
Got it now, This kind of points are important to know, I think there should be some document for Rules of Select/Option or Radio etc.. It would be good to learn from it.
Anyway thank you very much for helping...