Welcome Guest, Not a member yet? Register   Sign In
Can you insert an if condition in a view file?
#1

[eluser]titanite[/eluser]
Hi guys,

I'm really new at this, so please be patient with me. :cheese:

I'm doing up a movie database, and I have a page which has all the listings of the movie names. By clicking on Read More, one arrives at the full movie review.

This is my controller, which I name movie.php.

Code:
class Movie extends Controller {

    function Movie()
    {
        parent::Controller();
    }

    function movie_review()
    {
        $this->load->model('Movie_model');
        $id = $this->uri->Segment(3);
        $data['info'] = $this->Movie_model->get_review($id);
        $this->load->view('movie_view', $data);
    }
}

This is my Model, which I use to retrieve all information about a movie, which I call movie_model.php

Code:
class Movie_model extends Model {

    function Movie_model()
    {
        parent::Model();
    }

    function get_review($id)
    {
        $this->db->where('id', $id);
        $q = $this->db->get('movie_review');
        $info = $q->row();
        return $info;
    }

}

Now comes my view file. The issue is, I'd like to display a co-director IF he exists. But the IF condition just does not work.

Code:
<h2>Title: &lt;?=$info->title; ?&gt;</h2>
<h3>Directed by: &lt;?=$info->director_1; ?&gt;&lt;? if($info->director_2) { echo ", $info->director_2";} ?&gt;</h3>

What I get is, the code after $info being printed entirely:

director_2) { echo ", $info->director_2";}; ?&gt;

Can someone help me? Undecided
#2

[eluser]The Wizard[/eluser]
hello, yes you can.

probbebly your server does not support short php tags.

try setting in the config.php the value rewrite short tags to TRUE or just change the
&lt;? 's to &lt;?php .

it should do the trick Smile
#3

[eluser]titanite[/eluser]
Hi!
Thanks for your reply, unfortunately, it does support short tags, I've tested it.
Don't think it's a problem with short tags, otherwise the other variables like $title and $director_1 would not have been displayed.

Sad
#4

[eluser]The Wizard[/eluser]
zip and send your code Smile
#5

[eluser]titanite[/eluser]
Hi there!
Here's the zip file of the files I was talking about.
Many thanks!! I hope I'll be able to find the solution soon..
#6

[eluser]The Wizard[/eluser]
hello Smile

i created a database for it, worked out of the box.

i still vote for the problem on your server platform.

if you use, wamp, please try with xamp. if you use xamp,
try something else (wamp but be aware wamp does not
support short tags out of the box)

http://yfrog.com/esscreenshot20100418at355p
#7

[eluser]cahva[/eluser]
herrkaleun whats with this anti-wamp attitude? Smile With wamp this works also no problemo.
If you are working on a live server, check that the files have been transferred correctly. If using FTP, text files should be transferred in ascii, not binary(unless transferring binary text files).

Also in config.php, set rewrite_short_tags to true. That will make sure your app will work also in server with short tags disabled(and will rewrite short tags only if they are disabled).
Code:
$config['rewrite_short_tags'] = TRUE;
#8

[eluser]The Wizard[/eluser]
[quote author="cahva" date="1271625535"]herrkaleun whats with this anti-wamp attitude? Smile With wamp this works also no problemo.
If you are working on a live server, check that the files have been transferred correctly. If using FTP, text files should be transferred in ascii, not binary(unless transferring binary text files).

Also in config.php, set rewrite_short_tags to true. That will make sure your app will work also in server with short tags disabled(and will rewrite short tags only if they are disabled).
Code:
$config['rewrite_short_tags'] = TRUE;
[/quote]

selam cahva Smile

wamp kinda drove me nuts one day, when i was a apperentice php programmer. i got a blank screen the whole day
while exact the same code was working on xampp Smile

nowadays i use mamp and textmate. they are very good together Smile
#9

[eluser]titanite[/eluser]
Hi guys,

Thanks.. the $config['rewrite_short_tags'] = TRUE;
I've doubled checked that. It is not a problem of that, otherwise, the other variables would not have shown.

I'm using XAMPP, do you seriously think it is a problem of my XAMPP installation??
#10

[eluser]The Wizard[/eluser]
[quote author="titanite" date="1271635909"]Hi guys,

Thanks.. the $config['rewrite_short_tags'] = TRUE;
I've doubled checked that. It is not a problem of that, otherwise, the other variables would not have shown.

I'm using XAMPP, do you seriously think it is a problem of my XAMPP installation??[/quote]

why not try wamp and prove us wrong in a minute? Smile




Theme © iAndrew 2016 - Forum software by © MyBB