Welcome Guest, Not a member yet? Register   Sign In
New to CI - Small bugs in the view
#1

[eluser]amites[/eluser]
Hello,

to jump right to it I'm having trouble with my first CI site and am running into 2 challenges that are giving me trouble

the first is that the CSS is not rendering once I switched from a local windows server to a Linux server

I updated the config.php to reflect the new root URL, I've checked the code and it is rendering the link properly

the other is an error that is showing up with the parser,

Fatal error: Call to a member function parse() on a non-object in /system/application/views/rsvp.php on line 7

which looks like:

Code:
<?php
        $this->load->library('parser');
        $data = array(
            'title' => 'RSVP',
            'header' => ''
            );
        $this->parser->parse('partial/header', $data); // Line 7
        $this->load->view('partial/menu');
?>

the control is:

Code:
<?php

class Rsvp extends Controller {

function Rsvp(){
    parent::Controller();
    $this->load->helper('url');
    $this->load->helper('form');
    $this->load->library('validation');
}

function index(){

    // set validation rules
    $rules['name']="required";
// more rules
    $this->validation->set_rules($rules);
    if ($this->validation->run()==FALSE){

        $this->load->view('rsvp');

    } else{
        // display success web page
        $this->load->view('validator_success');
    }
}
}
?>


any thoughts will be greatly appreciated
#2

[eluser]amites[/eluser]
got the css bug fixed, was being sloppy in the config file,

though the parse error has be scratching my head,

ran into this same problem with a 2nd page and wrote around it, would like to understand it
#3

[eluser]jtkendall[/eluser]
Hi, the error you're receiving regarding line 7 means that you're trying to use "$this" outside of a class definition.
#4

[eluser]jtkendall[/eluser]
I just tested and the issue is that you are trying to load a library in the view. Move
Code:
$this->load->library('parser');
to just after
Code:
$this->load->library('validation');
and it should work.
#5

[eluser]amites[/eluser]
line 2 loads the parser to the $this object,

that's what is throwing me off, I am able to load a library inside the template (just the template parser [flame shield] ) but cannot use it on the same object that loaded it?

has anyone run into a challenge like this before?
#6

[eluser]jtkendall[/eluser]
Did you try what I suggested? You cannot use
Code:
$this
outside of a class definition. So since your view file is not a class, but a regular PHP file, you're just including the Parser library. You're not initializing it.

If you insist on loading the library in your view you need to first initialize the class and then call the parse method like this:

Code:
<?php
        $this->load->library('parser');
        $parser = new CI_Parser();
        $data = array(
            'title' => 'RSVP',
            'header' => ''
            );
        $parser->parse('partial/header', $data);
        $this->load->view('partial/menu');
?>

Though IF you load it in the controller you can use your code as is.
#7

[eluser]amites[/eluser]
Thank you,

your suggestion worked I just wasn't understanding the difference.

I appreciate your patience, think I like this MVC thang




Theme © iAndrew 2016 - Forum software by © MyBB