codeigniter

MVC best practice

允我心安 提交于 2020-01-03 20:07:13
问题 I'm new to MVC (i'm using codeigniter) and was wondering where I should put a "cut_description" function. My model retrieves a list of events including their description. If the description is too long, I would need to cut it after the first n words, and add a "read more" link, so the view doesn't get too cluttered. What would be the best practice? add the logic to cut after n words to the model add the logic to the controller add it to the view? I think 3 would be the easier (I have to loop

codeigniter data passing controller->library->view

不想你离开。 提交于 2020-01-03 19:04:43
问题 I have a codeigniter problem. Im trying to send data from a controller , to a library , to a view. i get this error in the view: Message: Undefined variable: crimes FileName: views/crime_view.php Line: 45 while debugging , i dump the $data variable, and get: that shows that my variables exist. in the library , im getting the controller data by using: $data[] = $componentData; that would not work in this case. but if i in the library do: $data['crimes'] = "test"; then it will work. for some

Codeigniter caching issue when dealing with query string parameters

て烟熏妆下的殇ゞ 提交于 2020-01-03 18:39:50
问题 Greetings, I'm writing a CI web application which implements the standard file caching functionality as such: $this->output->cache(n); I'm using a combination of segments and query string parameters, and appear to be experiencing an issue as a result. What I'm seeing in my use cases and in the Output class code is that the caching is solely segment based. As such, http://www.example.com/segment/?q=foo and http://www.example.com/segment/?q=bar are treated as identical requests. Does anyone

How to include CodeIgniter generated pages?

╄→尐↘猪︶ㄣ 提交于 2020-01-03 17:16:13
问题 What would be the easiest way to include a CI file? Let's say I want to include http://example.com/ci/index.php/mycontroller/ on example.com example.com doesn't run CI and I can't do include('ci/index.php/mycontroller'). 回答1: As I couldn't seem to invoke the CI controller's functions, I decided it's easiest to simply load the page with jQuery: $('#myDiv').load('ci/index.php/mycontroller', {}, function(){ $('#myDiv #loading').hide(); $('#myDiv #data').slideDown(500); }); 回答2: Assuming you have

How to include CodeIgniter generated pages?

萝らか妹 提交于 2020-01-03 17:16:12
问题 What would be the easiest way to include a CI file? Let's say I want to include http://example.com/ci/index.php/mycontroller/ on example.com example.com doesn't run CI and I can't do include('ci/index.php/mycontroller'). 回答1: As I couldn't seem to invoke the CI controller's functions, I decided it's easiest to simply load the page with jQuery: $('#myDiv').load('ci/index.php/mycontroller', {}, function(){ $('#myDiv #loading').hide(); $('#myDiv #data').slideDown(500); }); 回答2: Assuming you have

Codeigniter using foreach in view

萝らか妹 提交于 2020-01-03 17:01:09
问题 I'm using Codeigniter on an Apache xampp set up and attempting to use foreach in a view for the first time and I just can't get it to work. My Controller code: class Test extends CI_Controller { public function index($page = 'testv') { if ( ! file_exists(APPPATH.'/views/'.$page.'.php')) { show_404(); } $this->load->model('testm'); $data['news'] = $this->testm->get_news(); $this->load->view('headder'); $this->load->view($page, $data); $this->load->view('footer'); } } My Model: class Testm

How to check if email already exists in db with CodeIgniter

旧街凉风 提交于 2020-01-03 16:58:31
问题 I am doing application in CodeIgniter. I don't know how to compare email against db in CodeIgniter, please any one, help me. Controller public function signup() { $this->load->view('signup'); } public function savedata(){ $this->load->library('form_validation'); $this->form_validation->set_rules('firstname', 'firstname', 'required'); $this->form_validation->set_rules('lastname', 'lastname', 'required'); if ($this->form_validation->run() == TRUE) // Only add new option if it is unique {

Select only unique values from a column in codeigniter

岁酱吖の 提交于 2020-01-03 14:24:13
问题 i have a table like this name|subjects|location ...................... BUET|CSE|Dhaka BUET|EEE|Dhaka RUET|CE |Rajshahi RU |CE |Rajshahi here all the rows are distinct.And if I use $this->db->select('*') and $this->db->distinct() it would select all the rows of BUET but i only want like this name|subjects|location ...................... BUET|CSE|Dhaka RUET|CE |Rajshahi RU |CE |Rajshahi That means only the first column must be distinct and select all the columns as usual.And it would work if i

Select only unique values from a column in codeigniter

老子叫甜甜 提交于 2020-01-03 14:24:08
问题 i have a table like this name|subjects|location ...................... BUET|CSE|Dhaka BUET|EEE|Dhaka RUET|CE |Rajshahi RU |CE |Rajshahi here all the rows are distinct.And if I use $this->db->select('*') and $this->db->distinct() it would select all the rows of BUET but i only want like this name|subjects|location ...................... BUET|CSE|Dhaka RUET|CE |Rajshahi RU |CE |Rajshahi That means only the first column must be distinct and select all the columns as usual.And it would work if i

how to get only not null element count in array php

ε祈祈猫儿з 提交于 2020-01-03 13:10:10
问题 i want to get only not null values count in that array , if i use count() or sizeof it will get the null indexes also . in my case i have an array like this Array ( [0] => ) the count is 1 . but i want to get the not null count , inthis case it should be 0 , how can i do this , please help............................ 回答1: simply use array_filter() without callback print_r(array_filter($entry)); 回答2: $count = count(array_filter($array)); array_filter will remove any entries that evaluate to