模型 - 视图 - 控制器(MVC)是软件工程中使用的架构模式。对于Microsoft ASP.NET MVC,请改用[asp.net-mvc]或[asp.net-core-mvc]标签。对于Spring MVC,请改用[spring-mvc]标签。
$this->load->view('confirm_data_v', $a_1, $a_2);
public function get_all_subjects() { return $this->db->get('subjects'); }
如何通过控制器的模型方法结果到codeigniter中的查看 我想创建简单的搜索功能。我跟随一些例子。但是我无法获得结果。 查看页面
Controller function search_keyword() { $keyword = $this->input->post('keyword'); $data['results'] = $this->mymodel->search($keyword); $this->twig->display('result_view.php', $this->data); //$this->load->view('result_view.php', $data); } 模型 function search($keyword) { $this->db->like('item_name', $keyword); $query = $this->db->get('bracelets'); return $query->result(); } 改变 $this->twig->display('result_view.php',$this->data); to $this->load->view('result_view.php',$data); 使用此功能 function search_keyword() { $keyword=$this->input->post('keyword'); $data['results']=$this->mymodel->search($keyword); $this->twig->display('result_view.php',$data); }
呼吸引用的变量并未被渲染为其在CodeIgniter Active Record查询中的值
有人可以在代码上帮助我完成我的搜索功能吗?我是新的php和IM使用Codeigniter框架进行开发。 搜索视图 <div id="admin-col"> <div> <?php echo form_open('search_admin/search_admins'); ?> <?php $data = array('name' => 'search', 'id' => 'search'); echo form_input($data); ?> <?php $data = array( 'name' => 'submit', 'id' => 'submit', 'value' => 'Search Admin' ); echo form_submit($data); ?> </div> Controllerclass Search_admin extends CI_Controller { function __construct() { parent::__construct(); $this->load->helper(array('form', 'url')); $this->load->library('form_validation'); $this->load->library('security'); $this->load->library('tank_auth'); $this->load->model('users/usermodel'); } function index() { if (!$this->tank_auth->is_logged_in()) { redirect('/auth/login'); } else { $data['user_id'] = $this->tank_auth->get_user_id(); $data['username'] = $this->tank_auth->get_username(); } } function search_admins() { $data['query']=$this->usermodel->search_admins( $this->input->post('search') ); $this->load->view('admin/users/search_result', $data); } } 模型 class UserModel extends CI_Model { function _construct() { parent::_construct(); $this->load->helper(array('form', 'url')); $this->load->library('form_validation'); $this->load->library('security'); $this->load->library('tank_auth'); $this->load->model('users/usermodel'); $this->load->database(); } function search_admins($search) { return $query = $this->db->get_where('users', array('username =' => '$search'))->result(); } } the结果查看 <div id="admin-col"> <table> <tr> <th>ID</th> <th>Username</th> <th>Email Address</th> <th>Actions</th> </tr> <?php foreach ($query as $row) { ?> <tr> <td><?php print $row->id; ?></td> <td><?php print $row->username; ?></td> <td><?php print $row->email; ?></td> <td> <?= anchor('userslist/get_Admin/' . $row->id, 'Edit');?> | <?= anchor('userslist/deleteAdmin/' . $row->id, 'Delete'); ?> </td> </tr> <?php }?> </table> </div> 你有 array('username ='=> '$search') 在您的search_admins()函数 array('username'=> $search) instead
我想在我的模型中从称为司法管辖区的表中进行查询。 现在,我希望此查询提供有效的MySQL结果资源。即,我想将结果传递到mysql_fetch_array()。 如果我...
Controller: [update] //only first page displays data correctly but pager +1 using pagination displays user data only not getting orders as first page when I print_r($orders) in all pages I get correct orders but in the table the inner foreach doesn't work public function index($page_id = 1) { $perPage = 25; $offset = ($page_id - 1) * $perPage; if ($offset < 0) { $offset = $perPage; } $lang_id = $this->data['active_language']->id; $config['base_url'] = base_url() . "reports/myController/index/"; $config['per_page'] = $perPage; $config['first_link'] = FALSE; $config['last_link'] = FALSE; $config['uri_segment'] = 4; $config['use_page_numbers'] = TRUE; $config['first_link'] = lang('first_page'); $config['last_link'] = lang('last_page'); $config['first_tag_open'] = '<li>'; $config['first_tag_close'] = '</li>'; $config['last_tag_open'] = '<li>'; $config['last_tag_close'] = '</li>'; $config['next_tag_open'] = '<li>'; $config['next_tag_close'] = '</li>'; $config['prev_tag_open'] = '<li>'; $config['prev_tag_close'] = '</li>'; $config['num_tag_open'] = '<li>'; $config['num_tag_close'] = '</li>'; $config['cur_tag_open'] = '<li><strong>'; $config['cur_tag_close'] = '</strong></li>'; $config['display_pages'] = TRUE; $orders_serials_ids = $this->myModel->get_orders_serials_ids(); $config['total_rows'] = $this->myModel->count_orders(); $this->pagination->initialize($config); $users = $this->myModel->users_merchants($perPage, $offset); $this->data['users'] = $users; $user_orders = array(); foreach ($users as $user){ $user_orders[$user->user_id] = $this->myModel->get_orders($user->user_id); } View: <table> <tr> <th> <?php echo 'user';?> </th> <th> <?php echo 'email';?> </th> <th> <?php echo 'device id';?> </th> </tr> <?php foreach($users as $val){ ?> <tr> <td> <?=$val->user_id?> </td> <td> <?php echo $val->email;?> </td> <td> <?php echo $val->device_id;?> </td> </tr> <?php $order = array(); //empty the variable before each loop foreach($orders[$user->user_id] as $order){ echo '<tr><td colspan="4">'. date('Y-m',$order->unix_time). ' -> '.round($order->amount2,2).'</td></tr>'; } } ?> </table> <ul class="pagination"><?php if($pagination) echo $pagination;?></ul> user id user name user email 1 Mike [email protected] order:10 order total:50 order date: 2016-09-12 order:12 order total:100 order date: 2016-09-14 2 Tom [email protected] order:15 order total:80 order date: 2016-09-13 order:16 order total:120 order date: 2016-09-14 order:17 order total:140 order date: 2016-10-10
我有一个名为付款的表,该表名为indexorder,当我添加新付款时所需的一切,添加函数将首先检查如果indexorder列中有任何值
cannot加载codeigniter中的名为“数据库”的库
I下载了最后一个版本的Codeigniter,我尝试运行一个简单的应用程序。该代码在没有数据库的情况下完美工作,但是当我添加此信息时 $ autoLoad ['libraries'] = array('database'); 页面...
$CI =$ get_instance(); $CI->load->database();