阅读更多 Codeigniter 的功能


read more function with codeigniter

>我正在尝试在codeigniter中创建一个readmore函数,其中readmore链接将链接到一个控制器,该控制器将显示有关该特定ID的所有数据。我对如何去做有点困惑...我试过了。。。

<?php 
                    $research_detail_url = site_url()."/research/research_details";
                    //echo json_encode($research)
                    if($research)
                    {
                        foreach ($research as  $_research) {
                            $author = $_research->author;
                            $content = $_research->content;
                            $dsubmitted = $_research->dsubmitted;
                            echo "<div class='menu-collapse'> <h5>$author</h5>";
                            echo "<p>";
                            echo "<span class='support_text'>$content <span><br />";
                            echo "<span class='support_text'>$dsubmitted <span><br />";
                            echo "<a href='$research_detail_url' target='_blank' style='text-decoration:underline; color:#0088cc;'>
                            read more &raquo; </a>";
                            echo "</p> </div>";
                        }
                    }
                    ?>

但我似乎没有得到任何结果...我需要帮助。。。这是我的控制器功能.....

public function research_details($id='')
    {
        if(!$id)
        {
            echo "Project Id required";
            return;
        }   

        $_result = $this->projects_model->get_project($id);
        if($_result)
        {// success in fetching data hurray
            $result['projects'] = $_result;
            $users_ids = $this->users_model->get_user_ids(); //return available user id's
            $groups_ids = $this->groups_model->get_group_ids(); //return available group id's
            //echo json_encode($users_ids);
            //echo json_encode($groups_ids);
            $group_record = $this->map_names_to_ids($users_ids , $groups_ids );
            $result['group_record'] = $group_record;


            //load the view
            $this->load->view('__includes__/header');
            $this->load->view('__includes__/boostrap_responsive');
            $this->load->view('projects/project_panel', $result);
            $this->load->view('__includes__/footer_scripts');
            $this->load->view('__includes__/wijmo_file_jquery');
            $this->load->view('__includes__/footer');
        }
        else
        {
            exit("An Error occured in fetching the requested project");
        }
    }

这是我的模型.....

<?php
class research_model extends CI_Model {

    function add()
    {
        $this->db->insert('research',$_POST);
        if($this->db->_error_number())
        {
            return $this->db->_error_number();
        }
    }
    function update($article_id, $data_fields = NULL){
        if($data_fields == NULL)
        {
            $this->db->where("article_id =".$article_id);
            $this->db->update('research',$_POST);
        }
        else
        {
            $this->db->where("article_id =".$article_id);
            $this->db->update('research',$data_fields);
        }
        $is_error = $this->db->_error_number();
        if($is_error){
            echo $is_error;
        }
        return TRUE;
    }
    function delete($id){
        $this->db->where("article_id =".$id);
        return $this->db->delete('research');
    }
    //return the research with this id
    function get_research($id){
        $this->db->where("article_id =".$id);
        $query = $this->db->get('research');
        if ($query->num_rows() > 0){
            return $query->row_array();
        }
        else
            echo $this->db->_error_message();
            return FALSE;
    }
    //return the available research in the table
    function get_research_all(){
        $query = $this->db->get('research');
        if ($query->num_rows() > 0)
        {
            foreach($query->result() as $row)
            {
                $result[]   =   $row;
            }
            return $result;
        }
    }


}

和我的整个控制器.....

<?php
class Research extends Public_Controller
{
    function __construct()
    {
        parent::__construct();
        $this->load->model('research_model');       
    }
    function index()
    {
        if($this->ion_auth->is_admin())
        {
            $result =   $this->research_model->get_research_all();
            $data   =   array(
                'main_content'  =>  'research/index',
                'research'          =>  $result
            );
            $this->load->view("loader", $data);
        }
        else
        {
            redirect('home');
        }
    }//END INDEX

    // public view
    function current()
    {
        $result = $this->research_model->get_research_all();
        $data =  array('research' => $result); 
        $this->load->view('__includes__/header');
        $this->load->view('__includes__/navbar');
        $this->load->view('research/current', $data);
        $this->load->view('__includes__/footer');
    }
    function add()
    {
        if($this->ion_auth->is_admin())
        {
            $this->load->view("loader",array('main_content'=>"research/add_research"));
        }
    }//END ADD
    function edit($id='')
    {
        if(! $id)
        {
            echo "research Id required";
            return;
        }
        $result =   $this->research_model->get_research($id);
        if( ! $result)
        {
            echo "Nothing to edit";
            return;
        }
        $result['main_content'] =   "research/add_research";
        $this->load->view("loader",$result);
    }//END EDIT
    function delete($id='')
    {
        if(! $id)
        {
            echo "Id required";
            return;
        }
        $this->research_model->delete($id);
        $this->get_research();
    }//END DELETE
    function submit($id='')
    {
        //validate form [perform validation server-side to make sure of fields]
        $this->load->library('form_validation');
        $this->form_validation->set_rules('author', 'Author', 'trim|required|min_length[4]');       
        if ($this->form_validation->run() == FALSE){
            //ajax data array
            $data   =   array(
                'server_validation'     =>  validation_errors()
            );
            echo str_replace('''/', '/', json_encode($data));
        }
        else{
            if($id){
                $result     =   $this->research_model->update($id);
                $content    =   "article has been UPDATED successfully";
                //$retArr["content"] = $content;
                //echo json_encode($retArr);
            }
            else{
                $result     =   $this->research_model->add();
                $content    =   "article has been CREATED successfully";
                //$retArr["content"] = $content;
                //echo json_encode($retArr);
            }
            //if duplicate key
            if($result == 1062){
                //ajax data array
                $data   =   array();
                    $data['is_valid']   =   0;
                echo json_encode($data);
            }else{
                //ajax data array
                $data   =   array(
                    'is_valid'  =>  1,
                    'content'   =>  $content
                );
                echo json_encode($data);
            }
        }//end ELSE form valid
    }//END SUBMIT
    public function research_details($id='')
    {
        if(!$id)
        {
            echo "Project Id required";
            return;
        }   

        $_result = $this->research_model->get_research($id);
        if($_result)
        {// success in fetching data hurray
            $result['article'] = $_result;

            //load the view
            $this->load->view('__includes__/header');
            $this->load->view('__includes__/boostrap_responsive');
            $this->load->view('research/research_details', $Aresult);
            $this->load->view('__includes__/footer_scripts');
            $this->load->view('__includes__/wijmo_file_jquery');
            $this->load->view('__includes__/footer');
        }
        else
        {
            exit("An Error occured in fetching the requested project");
        }
    }//END EDIT
}
?>

我的公共控制器

<?php 
abstract  class Public_Controller extends CI_Controller
{
    public $about_data;
    function __construct()
    {
        parent::__construct();
        //Making This variable availale for the whole site
        $this->load->model('about_model');
        $this->load->model('captcha_model');
        //get your data
        $this->about_data = $this->about_model->get_abouts();   

    }
}
?>

我看到了几个问题:

  1. 在您看来,您没有关闭span标记。你需要 </span>

  2. 在您看来,您正在创建链接,但您不是包括控制器中需要的 ID。我的意思如下:

    首先,创建此$research_detail_url = site_url()."/research/research_details";

    然后echo "<a href='$research_detail_url' target='_blank' style=''>read more</a>";

    如您所见,您的 URL 在创建时没有 ID。你应该做的是这样的:$research_detail_url = site_url()."/research/research_details/31";其中31是一个随机ID。您需要提供所需的正确 ID,以便将其传递给您的控制器。您的控制器当前正在分配一个空白 ID,因为没有传递任何 ID,这就是为什么您最终得到"需要项目 ID"的结果的原因