如何通过codeigniter中的函数发送值

时间:2016-12-19 05:58:20

标签: codeigniter

public function index_pagination(){

        $this->load->library("pagination");
    $config = array();
    $config["base_url"]    = base_url("index/index");
    $config["total_rows"]  = $this->index_model->record_count();
    $config["per_page"]    = 2;
    $config["uri_segment"] = 3;

    // Styling pagination
    $config["full_tag_open"] = "<ul class='pagination'>";
    $config["full_tag_close"] = "</ul>";
    $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 class='active'><a>";
    $config["cur_tag_close"] = "</li></a>";

    $this->pagination->initialize($config);

    $page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
    $data["page"] = $this->index_model->fetch_products($config["per_page"], $page);
    $data["links"] = $this->pagination->create_links();
}

public function index(){

$this->index_pagination();

$this->load->view('frontend/index', $data);
}

如何通过索引功能将$data["page"]$data["links"]index_pagination()函数传递到我的视图文件?

2 个答案:

答案 0 :(得分:0)

你可以这样做..

<?php

 public function index(){

    $data = array();
    $data = $this->index_pagination();

    $this->load->view('frontend/index', $data); 
    }

public function index_pagination(){

    $this->load->library("pagination");

    $config = array();
    $config["base_url"]    = base_url("index/index");
    $config["total_rows"]  = $this->index_model->record_count();
    $config["per_page"]    = 2;
    $config["uri_segment"] = 3;

    // Styling pagination
    $config["full_tag_open"] = "<ul class='pagination'>";
    $config["full_tag_close"] = "</ul>";
    $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 class='active'><a>";
    $config["cur_tag_close"] = "</li></a>";

    $this->pagination->initialize($config);

    $page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
    $data["page"] = $this->index_model->fetch_products($config["per_page"], $page);
    $data["links"] = $this->pagination->create_links();
    return $data;
}

答案 1 :(得分:0)

我在我的控制器中编写了两个简单的函数,并使用它。这可能无法回答你的问题,但至少你要用它去干。

#include <iostream>
#include <string>
using namespace std;

int main()
{
string username1="Varun";
string username2="Agne";
string username3="Geetha";             
string username4="Mohan"; //Usernames for accounts
string pass1="PassworD";
string pass2="PASSWORD"; //Passwords for accounts
string pass3="password";
string pass4="Password";
string Uattempt; //User input for username
string Pattempt; //User input for password


cout << "Please enter your username.\n";
cin >> Uattempt;
cout << "Please enter your password \n";   //Asks for username and password entry by user
cin >> Pattempt;

if(Uattempt!=username1 || username2 || username3 || username4)
{
    cout << "Access Denied. Incorrect username or password. Please retry.\n";  //If username does not match possible entries, program will ask to retry
}
if(Pattempt !=(pass1||pass2)&&(pass3||pass4)
{
    cout << "Access Denied. Incorrect username or password. Please retry.\n";  //If password does not match possible entries, program will ask to retry
}
if (Uattempt&&Pattempt==username1&&pass1||username2&&pass2||username3&&pass3||username4&&pass4)
{
    cout << "Access Granted. Welcome " + <<Uattempt<< + ".\n";
}
else
{
    return 0;
}
}

尝试使用您的代码。 您可以访问此存储库以了解更多https://github.com/kishor10d/Admin-Panel-User-Management-using-CodeIgniter