Welcome Guest, Not a member yet? Register   Sign In
Moving CI from php4 to php5
#1

[eluser]pifantastic[/eluser]
Hello, I am very new to CI but I have a lot of experience with MVC frameworks. I am in the process of moving a CI app that was developed on a PHP4 server to a PHP5 server. I am having a lot of trouble with the upgrade. I have found that there are several cases where the code accesses the controller from the view. For some reason this does not work in PHP5. For exmaple, in several views, I find something like this:

Code:
<?php
<h3>blah blah</h3>
<div id="show">&lt;?= $this->load->view('myaccount/show') ?&gt;</div>
<div id="edit">&lt;?= $this->load->view('myaccount/edit') ?&gt;</div>
?&gt;

This doesn't seem to throw any sort of error, it just doesn't work as expected. The view that gets displayed is this:
Code:
<h3>blah blah</h3>
<div id="show">

So I was wondering if anyone had any experience with this or any ideas of how to fix the problem. I supposed I could load all the views in the controller and assign them to view data variables, but this is a large application and that would take a lot of time.

Let me know if I can provide more information.

Thanks!
#2

[eluser]jaswinder_rana[/eluser]
Above should work as I am using it.

Can it be path issue? How are your views stored? As per your example, it should

application/views/myyacount/show.php
application/views/myyacount/edit.php

Now, I am not sure if it maybe because of your short tags. I had to turn short tags on my local server to make it work. I am not saying you din't already, I am just listing possible causes.

AND, as per your code, you already have PHP tags open. Is that in your code or happened when you posted here?

No Starting/Closing PHP tags
Code:
<h3>blah blah</h3>
<div id="show">&lt;?= $this->load->view('myaccount/show') ?&gt;</div>
<div id="edit">&lt;?= $this->load->view('myaccount/edit') ?&gt;</div>
#3

[eluser]pifantastic[/eluser]
Sorry, the tags were me just being careless when posting. Short tags are definitely turned on for my server. I tried changing the path to the view to no avail. Perhaps it is a configuration issue of some sort? CI confuses me the way it has a base CI_loader object.
#4

[eluser]pifantastic[/eluser]
This problem isn't just for loading views either. Here and there I find code in a view referencing a controller method like:

Code:
&lt;?php
if ($this->logged_in()) {
echo '<h1>welcome!</h1>';
}
?&gt;

When this happens, I get an error like:
Quote:Fatal error: Call to undefined method CI_Loader::logged_in() in /blah/system/application/views/my_account/login_step.php on line 3
#5

[eluser]sophistry[/eluser]
maybe throw an echo and a second and third parameter into that view function call.

Code:
&lt;?php echo $this->load->view('myaccount/show','',TRUE) ?&gt;
#6

[eluser]pifantastic[/eluser]
Tried this:

Code:
<h3>blah blah</h3>
<div id="show">&lt;?php echo $this->load->view('myaccount/show', '', true); ?&gt;</div>
<div id="edit">&lt;?= $this->load->view('myaccount/edit') ?&gt;</div>

with same result Sad
#7

[eluser]jaswinder_rana[/eluser]
Sorry, not to nitpick (and just to make sure), is it myaccount or my_account (error shows different path)??
#8

[eluser]pifantastic[/eluser]
Okay, you are not nitpicking, you are just being smart. And I'm retarded. lol. Yes that was the problem. I just assumed that the view loading problem was related to the other problem I posted above. How this code worked before I have not clue.
#9

[eluser]mihailt[/eluser]
inside your views do like
Code:
$CI =& get_instance();
and replace all '$this->' to '$CI->', that should do it.

But it's not a good practice to call controller or model methods from your views.
#10

[eluser]Phil Sturgeon[/eluser]
[quote author="mihailt" date="1229610432"]inside your views do like
Code:
$CI =& get_instance();
and replace all '$this->' to '$CI->', that should do it.[/quote]

You don't need to do that. The CI object is available through $this in all views by default.




Theme © iAndrew 2016 - Forum software by © MyBB