Is there a way to combine these two functions? Category System - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5) +--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24) +--- Thread: Is there a way to combine these two functions? Category System (/showthread.php?tid=70072) |
Is there a way to combine these two functions? Category System - kirasiris - 02-15-2018 Hi, I'm working on a blog in which I need to display the categories it has, the problem is not that I can not get them, the problem is that I have to select the two values(category.id and category.title) in my add view , basically I have two inputs and I'm trying to get them together in just one single select input. Here is my functions, one for selecting the ID of the category, and a second one for the category's name. PHP Code: // Select Category ID Here is my method get_list located in the Post_categories_model: PHP Code: public function get_list() This is what I have in my add view: PHP Code: <!-- Post Subject ID --> and there's another problem, when displaying the category name in my post view(index.php; see below), I have this: PHP Code: <i class="fa fa-folder-open"></i> <a href="<?= base_url(); ?>posts/category/<?= $page->subject_id; ?>"><?= $page->subject_name; ?></a> it seems pretty simple but what can I do if there's more than one category per post? I hope you guys can help me. By the way this is what I have in my controller to display the posts: PHP Code: public function index() RE: Is there a way to combine these two functions? Category System - skunkbad - 02-15-2018 Combining is easy: PHP Code: if( $subject_list = $this->Posts_categories_model->get_list() ) RE: Is there a way to combine these two functions? Category System - kirasiris - 02-15-2018 (02-15-2018, 05:33 PM)skunkbad Wrote: Combining is easy: If I do that I just get them repated, the difference between them is the value would "value=1" or value="category-one". Not just that I' trying to add them here(the first two lines): PHP Code: $data = array( Doing it as you say it would just fill the subject_id input, and I want one input to fill the two values. How can I fill in the second value(subject_name) according to the subject_id? RE: Is there a way to combine these two functions? Category System - InsiteFX - 02-16-2018 CodeIgniter documentation see below the form_dropdown. SEE: form_multiselect RE: Is there a way to combine these two functions? Category System - skunkbad - 02-16-2018 I was merely combining the code you had in the first section. I was not trying to solve any problems. It is my perception that you may need to learn a little more PHP, and that perhaps you jumped on the CodeIgniter bandwagon a little early. Whatever the case, your learning experience is now, when you figure it out. RE: Is there a way to combine these two functions? Category System - kirasiris - 02-16-2018 (02-16-2018, 09:03 AM)skunkbad Wrote: I was merely combining the code you had in the first section. I was not trying to solve any problems. It is my perception that you may need to learn a little more PHP, and that perhaps you jumped on the CodeIgniter bandwagon a little early. Whatever the case, your learning experience is now, when you figure it out. Yes, I know but the combination was not the problem, I could do that by myself with my own example just like: PHP Code: $subject_options = array(); which is what I had before asking but I decided to divided them into two fuctions to make more clear what I was asking for. The problem of what I really want is to create a tag system like Wordpress in which the only necessary action is to select the cat/tag and it shows the link and its corresponding name in the front-end(per post)... Thats what I'm really having troubles with. I think WordPress call it "get term by id" or something like that. |