• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
View is not being loaded.

#1
[eluser]Raeony[/eluser]
I am currently testing out CodeIgniter, so I start by making a very simple member system in order to test very simple database manipulation.

Everything works just fine, the controller calls an addUser function that loads the "User" model and the addUser function of that model with the information that should be inserted into the database, no problems.

At the end, I made a very simple view, just so I can debug the response of the model, and at the same time test out views and data transfer from models to controllers and from controllers to views, but the view doesn't seem to show up. I am pretty sure the problem doesn't come from my code, but from the framework itself.

Here's my code :

CONTROLLER User.php (applications/controllers/User.php)
Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class User extends CI_Controller
{
protected $RESPONSE;
protected $USER_INFO;
  
public function __construct()
{
  parent::__construct();
}
public function index()
{
  $this->USER_INFO = array
  (
   'EMAIL'  => '[email protected]',
   'USERNAME'  => 'Dummy_user',
   'PASSWORD' => 'Dummy_pass'
  );
  $this->addUser($this->USER_INFO);
}

public function addUser($USER_INFO)
{
  $this->load->model('User_model','mdlUser');
  $this->RESPONSE = $this->mdlUser->addUser($USER_INFO);
}

public function _output()
{
  echo '_output called';
  if($this->RESPONSE == TRUE)
  {
   $RESULT = TRUE;
   $VIEW_DATA['USER_INFO'] = $this->USER_INFO;
   echo 'RESPONSE is TRUE';
  }
  else
  {
   $RESULT = FALSE;
   echo 'RESPONSE is FALSE';
  }
  
  $VIEW_DATA['RESULT'] = $RESULT;
  $this->load->view('User',$VIEW_DATA);
}
}

VIEW User.php (application/views/User.php)
Code:
<h1>Result :</h1><br/>
&lt;?php
if($VIEW_DATA['RESULT'])
{
  echo 'Process succeeded, added user with following information : <br/>';
  print_r($VIEW_DATA['USER_INFO']);
}
else
{
  echo 'Process failed';
}
?&gt;

And just in case ...

MODEL User_model.php (application/models/User_model.php)
Code:
&lt;?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class User_model extends CI_Model
{
/*
# ADD USER
# Parameters : - $DATA
#      An array containing
#      all the information
#      concerning the user
*/
public function addUser($DATA)
{
  # DATA RROCESSING #
  
  # SENDING TO DB #
  if($this->db->insert('users',$DATA))
  {
   return TRUE;
  }
  else
  {
   return FALSE;
  }
}
(There is more down there, but they are just empty functions)

This is the final result when loading the page :

Code:
_output called RESPONSE is TRUE

Output is called and there was no problems in the model.

I managed to get an error in the view, and here's what I get :

Code:
_output called RESPONSE is TRUE
Parse error: syntax error, unexpected T_IF in C:\xampp\htdocs\dyncms\dyncms\views\User.php on line 4

Output is called and there was no problems in the model.
Error in the view.

This means that the view is loaded, but not shown.

_________

More information :

- CodeIgniter version : 2.1.2 (latest)
- PHP: 5.3.8 running on Apache

_________

Thanks in advance !

#2
[eluser]ppwalks[/eluser]
what URL are you trying to load the view through in your controller?

#3
[eluser]Raeony[/eluser]
[quote author="ppwalks" date="1341487439"]what URL are you trying to load the view through in your controller?[/quote]

I am loading the controller with the following URL (dyncms is the app folder) :

http://localhost/dyncms/user
(I'm using URL rewriting)

The function that loads the view inside the controller :

$this->load->view('User',$VIEW_DATA);

The path leading to the view (dyncms is the app folder) :

webroot/dyncms/views/User.php

#4
[eluser]Nisha S.[/eluser]
Use $RESULT instead of $VIEW_DATA['RESULT'] in the view. When you pass an array the array elements are passed to the view.

#5
[eluser]Raeony[/eluser]
[quote author="Nisha S." date="1341487688"]Use $RESULT instead of $VIEW_DATA['RESULT'] in the view. When you pass an array the array elements are passed to the view.[/quote]

Thanks! That's good to know, the problem is still there though.
And by the way, I tried calling a view that only contains text, no PHP, the view still doesn't show.

#6
[eluser]Nisha S.[/eluser]
Are you getting the same mentioned error even without PHP code or empty screen?

#7
[eluser]Raeony[/eluser]
[quote author="Nisha S." date="1341490164"]Are you getting the same mentioned error even without PHP code or empty screen?[/quote]

No, I generated the error purposely to see if the view was being loaded, I just wrote "aaa" somewhere in the view's PHP code.

#8
[eluser]Nisha S.[/eluser]
Please check the log file if you have some error message over there. Also test by some echo before and after the view loading in controller and see if both appear in browser.

#9
[eluser]Raeony[/eluser]
[quote author="Nisha S." date="1341503289"]Please check the log file if you have some error message over there. Also test by some echo before and after the view loading in controller and see if both appear in browser.[/quote]

Nothing in the logs, and concerning the echo's, I did it and they are not being shown, nothing is shown at all, only the errors.

#10
[eluser]Aken[/eluser]
You're using the _output() method in the wrong way. It is meant to modify the output of views after they are loaded.

http://ellislab.com/codeigniter/user-gui...tml#output


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.