-1
        <div class="collapse navbar-collapse" id="navbar-collapse-1">
            <ul class="nav navbar-nav">
                <?php
                $this->load->model('cms_model');
                if (isset($article_data)) {

                } else {
                    $article_data = $this->cms_model->get_end_user_cms_menu(); (this line gives error)
                }
                 foreach ($article_data as $row) { ?>
                    <li class="dropdown">  <a href='<?php echo site_url('endusers/end_cms_controller/cms_type_selected?type_id=' . $row->type_id) ?>'>
                    <?php echo $row->type_name; ?>
                        </a> </li>
                <?php } ?>

            </ul>
            <div class="nav-search-wrap">
                <input class="txt-search" type="text" name="search" placeholder="Search">
            </div>
        </div><!-- /.navbar-collapse -->

This is the code from my view file it givs the error on line number i highlighted. The error is " Fatal error: Call to a member function get_end_user_cms_menu() on a non-object in E:\xampp\htdocs\Santulan\application\views\endusers\header.php on line 158"

  • Maybe you havent loaded model in your controller. Give us also some code from model. – cssBlaster21895 Sep 02 '15 at 08:55
  • 2
    You can not load model in view.That is strictly prohibited as this breaks the MVC. Load the model in controller and pass the data to the view. – Nazim Sep 02 '15 at 08:55
  • This is code from model public function get_end_user_cms_menu() { $query = "SELECT * FROM cms_types"; $result = $this->db->query($query); return $result->result(); } – Hemant Randive Sep 02 '15 at 08:58
  • Please help me on this i am new to this mvc pattern. The calling of the function is to load menu in the header.php – Hemant Randive Sep 02 '15 at 09:03
  • @HemantRandive You can actually do break the MVC Pattern in CI, but it is actually not a very good approach since it doesn't work that way in the first place.. but if you really wanna do so, [you can](http://stackoverflow.com/questions/21140379/codeigniter-calling-model-on-view#answer-21143860). – YouSer Sep 02 '15 at 09:14
  • Thank you user,it really works. I appreciate your help.I know its not a good practice to use this approach in MVC but you know its just time dependant for me, I will try not to use this approach in future. – Hemant Randive Sep 02 '15 at 09:26

2 Answers2

0

First, you must call $this->load->model('cms_model'); in your controller, not in your view. Then, in the controller also, not in your view, you could do:

    if (!isset($article_data)) {
         $article_data = $this->cms_model->get_end_user_cms_menu(); 
       }
   $data['list'] = '';
   foreach ($article_data as $row){
     $data['list'] .= "<li class=\"dropdown\">  <a href='".site_url('endusers/end_cms_controller/cms_type_selected?type_id=' . $row->type_id).">$row->type_name</a> </li>";
   }

Then, also in your controller, when you load the view, add $data:

$this->load->view('your_viwe', $data);

And in your view:

<div class="collapse navbar-collapse" id="navbar-collapse-1">
            <ul class="nav navbar-nav">
            <?php echo $list;?> 
            </ul>
            <div class="nav-search-wrap">
                <input class="txt-search" type="text" name="search" placeholder="Search">
            </div>
        </div>   

And your-re good to go.

Vali S
  • 1,471
  • 2
  • 10
  • 18
  • i want to diaplay a note in grocery crud codeigniter. how to add it when a column is displayed – Hemant Randive Sep 02 '15 at 11:13
  • please, elaborate. Be more explicit. As much detail as you can, so I can grasp the problem . – Vali S Sep 02 '15 at 11:16
  • when we write this $crud->set_field_upload('article_image', 'assets/uploads/articleImages'); when it display the columns,i want to add a note there that upload only specific size image when user upload the image – Hemant Randive Sep 02 '15 at 11:21
  • please refer to this article: http://www.grocerycrud.com/documentation/options_functions/callback_before_upload – Vali S Sep 02 '15 at 11:29
  • i am getting error on this array to string conversion $search_id['article_id']=$this->cms_model->search_tag_id($str); public function search_tag_id($str) { $qry="SELECT article_id FROM articles WHERE tags like '%$str%'"; $query=$this->db->query($qry); return $query->result(); } – Hemant Randive Sep 03 '15 at 12:09
  • Go to the file, to the line where error occurs : What is your code on that line? – Vali S Sep 03 '15 at 12:20
  • $search_id['article_id']=$this->cms_model->search_tag_id($str); This is the line where eror occurs – Hemant Randive Sep 03 '15 at 12:55
  • I cannot identify the problem, did you add another question, yet? If you didn't, please do, and specify all your code: controller, model, and view. Then post the link to your question here. I'm sure we'll solve the issue. – Vali S Sep 03 '15 at 13:00
  • links to controller and model file https://drive.google.com/open?id=0B5ZobNdpjE7yOGNLcHdFZ1k0VzA – Hemant Randive Sep 03 '15 at 13:06
  • These are the llinks to my g drive,files are there – Hemant Randive Sep 03 '15 at 13:09
  • i have given access to you – Hemant Randive Sep 03 '15 at 17:40
  • ok, I found the problem. Please go to Ask Question http://stackoverflow.com/questions/ask, post your question together with the content of function index in your Search_controller, and functions search_tag_id() and search_article() in your cms_model. After that, post the link to your question here. I'll post my answer right away. – Vali S Sep 04 '15 at 07:16
  • Hello webcrazymaniac they now allowing me to ask question says you can ask after 4 days....can you post your answer to my gmail coount please ..you can post answer after that when they allow me. Or add me on facebook please " hemant randive " place - amalner – Hemant Randive Sep 04 '15 at 12:12
  • How to add multiple checkboxes in grocery crud codeigniter and save them – Hemant Randive Sep 05 '15 at 09:29
0

About the other problem: The issue was inside your controller. I post the corrected version with explanatory comments:

 public function index(){
        $str=$this->input->post('search'); 
        $search_id=$this->cms_model->search_tag_id($str);      
        //echo  $id= $search_id; -> you cannot echo $search_id becouse it's an array: $query->result() from search_tag_id() model function.
        //$query->result() is allways an array
        //FOR DEBUGGING: when you want to see inside $query->result(), use: echo '<pre>'.print_r($query->result(), true).'</pre>';
        // instead you use:
        $id = $search_id->article_id;
        $search_data['article']=$this->cms_model->search_article($id);// function for search article
        if($search_data){
            $this->load->view('endusers/cms_view', $search_data); // this is ok, if you call for $article and $article_image inside the view
        }else{
            echo "No result found";
        }   
    }
Vali S
  • 1,471
  • 2
  • 10
  • 18