Welcome Guest, Not a member yet? Register   Sign In
[solved] CI loads not the right view after upgrading
#1

[eluser]SPeed_FANat1c[/eluser]
Hi,

I upgraded the site from 1.73 to 2.0.1 but when going to http://localhost/ubagynasCI2/ I get an error:

A PHP Error was encountered
Severity: Notice
Message: Undefined variable: content
Filename: views/info_page_view.php
Line Number: 2

and I see it loads not the right view, here is the controller code.
Code:
function index($offset = 0)
    {                
        $this->load->model('Nustatymai_model','nust');
        $this->load->model('News_model','News');
        $this->load->library('pagination');

        $config['base_url'] = base_url().'home/index/';
        $config['total_rows'] = $this->News->totalNews();
        $config['per_page'] = $this->nust->getNaujienu_sk_puslapyje();
        $config['first_link'] = 'Pirmas';
        $config['last_link'] = 'Paskutinis';
        $config['full_tag_open'] = '<div class = "pagination">';
        $config['full_tag_close'] = '</div>';
        
        $this->pagination->initialize($config);
        
        
        
        $this->data['current_menu'] = $this->where_is_pradzia_menu();
        $this->data['title'] = 'Ylakių globos namai';
        $this->data['meta'] = array(
                0 => '&lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /&gt;',
                1 => '&lt;meta name="Distribution" content="Global" /&gt;',
                2 => '&lt;meta name="Robots" content="index,follow" /&gt;',
                3 => '&lt;meta name="Keywords" content="Ylakiu globos namai, ylakiu seneliu namai" /&gt;',
                4 => '&lt;meta name="Description" content="Ylakių globos namų tinklalapis" /&gt;'
            );
                
        $this->data['news'] = $this->News->getNews($offset,$config['per_page']);
        $this->display('home_view');
    }

you see there is line

Code:
$this->display('home_view');

So it should load the home_view, not the info_page_view

The MY_Controller:

Code:
class MY_Controller extends CI_Controller{
  
  var $data;

  public function __construct(){
    parent::__construct();
    
    //default data
    $this->data['title'] = 'Ylakių globos namai';
    $this->data['meta'] = array(
                0 => '&lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /&gt;',
            );
    $this->data['javascript'] = '';
    $this->data['virsutinis_meniu'] = $this->get_top_menu();
    $this->data['current_menu'] = 99;    //99 reiskia joks meniu nera aktyvus

    
    //sidearui
    $this->data['links'] = $this->get_links();
    $this->data['banners'] = $this->get_banners();
    
    
    /*
    //footeriui, jie noresim dinaminiu duomenu
    $this->data['footer'] = $this->Views_model->data_for_footer();
    */        
  }
  
  /*
   * paduodam main sekcijos view faila, taip pat kaip ir this load view kai paduodume
   */
  function display($main_view){
  
       $this->load->vars($this->data);
      
     $this->load->view('header_view');
     $this->load->view($main_view);
     $this->load->view('sidebar_view');
     $this->load->view('footer_view');
  }
  
    private function get_top_menu()
    {
        $this->db->order_by('Eile','asc');
        $query = $this->db->get('virsutinis_meniu');
        return $query->result_array();
    }
    
    private function get_links()
    {
        $query = $this->db->order_by('vieta','asc')->get('nuorodos');
        return $query->result();
    }
    
    function get_banners()
    {
        $query = $this->db->order_by('queue','asc')->get('reklama');
        return $query->result();
    }
}

In routes.php there are such lines:

Code:
$route['default_controller'] = "home";
$route['scaffolding_trigger'] = "";

$route['((?!admin|admin_|galerija|home|test).*)'] = "home/info/$1";

In CI 1.73 it loads the right view. But it looks like it is not calling the index function in home controller. And calls home/info instead of it. Why could that be?
#2

[eluser]InsiteFX[/eluser]
Did you change all Controllers to CI_Controller and all Models to CI_Model ?
You need to also use the CI 2.0.X index.php file

Also this was added to application/config/routes.php
Code:
$route['404_override'] = '';

InsiteFX
#3

[eluser]SPeed_FANat1c[/eluser]
Quote:you change all Controllers to CI_Controller and all Models to CI_Model ?

Yes, actually for controller I only needed to change in MY_Contoller class, becasue controoller extend this. For model changed alse.

Quote:You need to also use the CI 2.0.X index.php file
The one in the root directory? Changed it.
Quote:Also this was added to application/config/routes.php

$route['404_override'] = '';

cannot see this in user_guide, but now added that line. After the $route['default_controller'] = "home";

And commented out $route['scaffolding_trigger'] = "";

But still the same..

Edit:

forget to tell - when I go to http://localhost/ubagynasCI2/home then it works well. So it simply does not reroute to that funciton when I go http://localhost/ubagynasCI2/
#4

[eluser]InsiteFX[/eluser]
Message: Undefined variable: content

I do not see this variable in any of the code you posted?

Where is variable conent?

This may be the problem here! You do not need this here place it right into the views &lt;head&gt;
Code:
$this->data['meta'] = array(
                0 => '&lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /&gt;',
            );

InsiteFX
#5

[eluser]SPeed_FANat1c[/eluser]
Quote:Message: Undefined variable: content

I do not see this variable in any of the code you posted?

Where is variable conent?

that is in another home controllers funciton:
Code:
function info($url_title)
    {
        $where = "psl_id = (SELECT psl_id FROM virsutinis_meniu WHERE nuoroda = '".$url_title."')";
        $query = $this->db->where($where)->get('info_psl');
        if($query->num_rows() > 0)
        {
            $row = $query->row();
            
            
            $this->data['title'] = $row->pavadinimas;
            $this->data['current_menu'] = $row->eil_nr;
            
            $this->data['meta'] = array(
                0 => '&lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /&gt;',
                1 => '&lt;meta name="Distribution" content="Global" /&gt;',
                2 => '&lt;meta name="Robots" content="index,follow" /&gt;'
            );
            if($row->meta_keywords != '')
                $this->data['meta'][] = '&lt;meta name="Keywords" content="'.$row-&gt;meta_keywords.'" />';
            if($row->meta_description != '')
                $this->data['meta'][] = '&lt;meta name="Description" content="'.$row-&gt;meta_description.'" />';
            $this->data['content'] = $row->tekstas;    
        }
        else $this->data_main['content'] =     'Nėra tokio puslapio';
        
        $this->display('info_page_view');
    }


Quote:This may be the problem here! You do not need this here place it right into the views &lt;head&gt;

$this->data['meta'] = array(
0 => '&lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /&gt;',
);

I could put inside the &lt;head&gt; instatnly, but I need such array anyway, because when I extend the MY_Conroller as you can see from function info I use the data['meta'] with more indexes, in some controllers I add keywords metadata to that array. And if I comment out it in constructor, then I get error

A PHP Error was encountered
Severity: Notice
Message: Undefined variable: meta
Filename: views/header_view.php
Line Number: 7
A PHP Error was encountered
Severity: Warning
Message: Invalid argument supplied for foreach()
Filename: views/header_view.php
Line Number: 7

of, course I could do checking if meta isset but I don't thing that the problem is in here somehow.

But the main problem that the function "info" is called when I go to http://localhost/ubagynasCI2/ - the index function should be called instead.


Edit: found one more thing:

when I comment out this line in routes.php:

Code:
$route['((?!admin|admin_|galerija|home|test).*)'] = "home/info/$1";

then there is no error when I go to http://localhost/ubagynasCI2/

so the problem is with routing. But I need this line because otherwise I cannot go to urls like this:

http://localhost/ubagynasCI2/contact that line helps to reroute to function "info"
#6

[eluser]InsiteFX[/eluser]
Well a lot of the Routing has changed in CI 2.0.X, so I would start looking there then.

I know a lot of users have had problems with setting the protocol in the config.php file some work and some do not work!

InsiteFX
#7

[eluser]SPeed_FANat1c[/eluser]
Quote:I know a lot of users have had problems with setting the protocol in the config.php file some work and some do not work!

changed uri_protocol from auto to

$config['uri_protocol'] = "QUERY_STRING";

and now home page works Big Grin but don't understand, there is now query strings in my urls. Now I need some testing if other things work Smile

Edit: thanks for helping Smile
#8

[eluser]InsiteFX[/eluser]
No problem!

Try the other ones until you find one that works for you.

InsiteFX
#9

[eluser]SPeed_FANat1c[/eluser]
tried all of them, and only QUERY_STRING works. Maybe you know what possible problems might be when I use QUERY_STRING ? At least for now I don't see any, other controllers work, ajax functions also work.
#10

[eluser]InsiteFX[/eluser]
Old saying! If it works leave it alone LOL

InsiteFX




Theme © iAndrew 2016 - Forum software by © MyBB