Welcome Guest, Not a member yet? Register   Sign In
I can't to do works two functions at same times.
#1

[eluser]masentinel900[/eluser]
I need declare some functions with different variables, these variables will content information fetched of the appropiate model across your controller.
The problem start in the moment that I need call the variables in the view file, By default only show me the variables that is declared in the index function, and the another show a error "indefined variable" And if I call the function across of URL don't works the first "index", Just works I called in the URL.
Please some that can help me...
#2

[eluser]vitoco[/eluser]
Maybe it's just me, but i didn't understand your explanation, please post some code or an example.

Slds
#3

[eluser]tpetrone[/eluser]
so I think your asking is how to return data from two different models from within the same controller, then load the data into the view.

Code:
$data1 = $this->your_model->get_some_data();

$data2 = $this->other_model->get_some_other_data();

$final_data = array($data1, $data2);

$this->load->view('your_view', $final_data);


or instead of $final_data.... below might work better.. I am sure there are several ways to get this done.


$data = array_merge($data1, $data2);

$this->load->view('your_view, $data);
#4

[eluser]skunkbad[/eluser]
[quote author="vitoco" date="1350060021"]Maybe it's just me, but i didn't understand your explanation, please post some code or an example.

Slds[/quote]

+1
#5

[eluser]masentinel900[/eluser]
Ok, I´m sorry if I don´t explain me of the better way.
Here I put a single example, The mine is a bit most hard.

If I need to make a page with Header, Body and Footer; And the controller will look like this:

Controller
Code:
function header()
{
   $data['header'] = "Here goes the Header content";
   $this->load->view('page', $data);
}
function body()
{
   $data1['body'] = "Here goes the body content";
   $this->load->view('page', $data1);
}
function footer()
{
   $data2['footer'] = "Here goes the footer content";
   $this->load->view('page', $data2);
}

So In the page file in the VIEWS I call that variables simply adding a php script with "echo $footer", "echo $header" and "echo $body".

My problem start when I try of add the three variables same time, I need use them in the same page.

I thought that were problem of Index.php and I´ve been trying of remove it but I don´t get it..

Many thanks to the people that interest in this post..
#6

[eluser]skunkbad[/eluser]
Code:
// Controller method
public function page()
{
$data = array(
  'header' => 'Here goes the Header content',
  'body'   => 'Here goes the Body content',
  'footer' => 'Here goes the Footer content'
);

$this->load->view('template', $data);
}

// Template view (/application/views/template.php)
<html>
<head>...</head>
<body>
<?php
  echo $header;
  echo $body;
  echo $footer;
?>
</body>
</html>
#7

[eluser]masentinel900[/eluser]
Thanks "Skunkbad", Do you have the reason.

But I need to make each one functions with content brought of a functions of a model.
So.

Model
Code:
class user extends CI_Model
{
function login($username, $password)
{
$this -> db -> select('*');
$this -> db -> from('usuario');
$this -> db -> where('username = ' . "'" . $username . "'");
$this -> db -> where('password = ' . "'" . MD5($password) . "'");
$this -> db -> limit(1);
  
$query = $this -> db -> get();
  
if($query -> num_rows() == 1)
{
     return $query->result();
}
  else
  {
   return false;
  }
}

function content()
{
  $query = $this->db->query('SELECT * FROM actas');
  foreach ($query->result_array() as $row)
  {
   echo $row['codigoagencia'];
   echo $row['nombreacta'];
   echo $row['rutaarchivo'];
   echo $row['descripcion'];
   echo $row['creadopor'];
   echo $row['modificadopor'];
   echo $row['fechadecreacion'];
   echo $row['fechademodificacion'];
  }
  return $query->fetch_assoc();
}
}

I use the function login for to make a loggin acces to my website and works perfect, But now I need brought information of different tables of my DB. Is by this that I need make several functions with different information.

Now I need to get this content of differents tables, pass to my controller for to define some rules and finally may show it in my view page.
#8

[eluser]skunkbad[/eluser]
Yeah, because it works

Code:
// Controller method
public function page()
{
$this->load->model('the_model');

$data = array(
  'header' => $this->the_model->get_header(),
  'body'   => $this->the_model->get_body(),
  'footer' => $this->the_model->get_footer()
);

$this->load->view('template', $data);
}

// Model
class The_model extends CI_Model{

public function get_header()
{
  return 'Here goes the Header content';
}

public function get_body()
{
  return 'Here goes the Body content';
}

public function get_footer()
{
  return 'Here goes the Footer content';
}

}

// Template view (/application/views/template.php)
<html>
<head>...</head>
<body>
<?php
  echo $header;
  echo $body;
  echo $footer;
?>
</body>
</html>
#9

[eluser]masentinel900[/eluser]
Sir skunkbad Again I give you very thanks. Is very important for me can fix it.

I going to test this solution that you proposed me.
I Would like to know if is possible to do works more than one function in the controller file..
#10

[eluser]skunkbad[/eluser]
[quote author="masentinel900" date="1350147407"]Sir skunkbad Again I give you very thanks. Is very important for me can fix it.

I going to test this solution that you proposed me.
I Would like to know if is possible to do works more than one function in the controller file..
[/quote]

Yes, you can have more than one function in a controller, but codeigniter considers them to be routes unless they are protected or private.




Theme © iAndrew 2016 - Forum software by © MyBB