Welcome Guest, Not a member yet? Register   Sign In
foreach question.
#1

I have a list of my $positions = array() in array below


PHP Code:
$positions = array(
'column_left',
'column_right',
'content_top',
'content_bottom'
);

foreach (
$tmpdata as $position => $module) {
if (
in_array($position$positions)) {
$data[$position] = $this->load->view($position$tmpdata[$position], TRUE);
}



In my foreach loop it gets the positions that are set in the database and then loads the view for it. But because a position may not be set in database it throws error like

Undefined variable: column_right

How can I make it not throw that type of error if can not find position then should be some thing like 


PHP Code:
$data['column_right'] = $this->load->view('column_right'''TRUE); 



PHP Code:
<?php

class Welcome extends CI_Controller {

public function 
__construct() {
parent::__construct();
$this->load->model('design/layout_model');
}

public function 
index() {
$layout_id $this->layout_model->getlayoutID($this->router->class);

$modules $this->layout_model->getlayoutsmodule($layout_id);

$tmpdata = array();

foreach (
$modules as $module) {

$name $module['name'];
   
   $this
->load->library('module/' $name);
   
   $tmpdata
[$module['position']]['modules'][] = $this->load->view('module/question_help'$this->$name->get(), TRUE);
}

$positions = array(
'column_left',
'column_right',
'content_top',
'content_bottom'
);

foreach (
$tmpdata as $position => $module) {
if (
in_array($position$positions)) {
    $data[$position] = $this->load->view($position$tmpdata[$position], TRUE);
}
}

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

There's only one rule - please don't tell anyone to go and read the manual.  Sometimes the manual just SUCKS!
Reply


Messages In This Thread
foreach question. - by wolfgang1983 - 04-16-2017, 02:59 AM
RE: foreach question. - by PaulD - 04-16-2017, 03:49 AM
RE: foreach question. - by wolfgang1983 - 04-16-2017, 03:15 PM



Theme © iAndrew 2016 - Forum software by © MyBB