• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Controller variable not being passed to view

#6
[eluser]Unknown[/eluser]
Here are the details from var_dump():

array(1) { [0]=> string(56) "http://www.dsfdsfdsffsfdsatechrepublic.com/5150-22-0.xml" }

The url in the array is obviously no good, and is set - the view is displayed. There are other valid urls in the OPML file that get loaded into the database as appropriate.

What's interesting is that the same code works in another function perfectly. The code shown above is for inserting feeds from an opml file. The code for inserting feeds manually works as intended when a bad url is provided. As such:

Code:
function Manual()
{
  //check credentials
  $creds = $this->check_creds();
  
   if($creds == TRUE)
   {
   $this->load->plugin(array('snagurls'));
   $user = $this->session->userdata('username');
   //Get each feed entered into the form - there will be a max of 5.
  
   $this->load->library('validation');
  
   $rules['feed1'] = "min_length[4]|max_length[255]|xss_clean";
   $rules['feed2'] = "min_length[4]|max_length[255]|xss_clean";
   $rules['feed3'] = "min_length[4]|max_length[255]|xss_clean";
   $rules['feed4'] = "min_length[4]|max_length[255]|xss_clean";
   $rules['feed5'] = "min_length[4]|max_length[255]|xss_clean";
  
   $this->validation->set_rules($rules);
   if($this->validation->run() == TRUE)
   {
//Create an array to hold each feed address.  Add the data from each input field (if it exists) to the array.
if(strlen($_POST['feed1']) > 4)
{
  $urlArray['newfeed1'] = @SnagUrlCleaner($_POST['feed1']);
  //echo $urlArray['newfeed1'];
}
if(strlen($_POST['feed2']) > 4)
{
  $urlArray['newfeed2'] = @SnagUrlCleaner($_POST['feed2']);
}
if(strlen($_POST['feed3']) > 4)
{
  $urlArray['newfeed3'] = @SnagUrlCleaner($_POST['feed3']);
}
if(strlen($_POST['feed4']) > 4)
{
  $urlArray['newfeed4'] = @SnagUrlCleaner($_POST['feed4']);
}
if(strlen($_POST['feed5']) > 4)
{
  $urlArray['newfeed5'] = @SnagUrlCleaner($_POST['feed5']);
}
foreach($urlArray as $url)
{
  $feedResult = @$this->Add_Feed($url, $user);
  
  if($feedResult == false)//the url has been returned due to an error
  {
   $urlError[] = $url;
  }
}
if(isset($urlError))
{
  
  $data['urlError'] = $urlError;
  $this->load->view('gs_error', $data);
}
else
{
  //redirect user to the feed settings page.
}
   }
   else
   {
//enter code for validation error
   }
  }
  else
  {
//this user is not validated...send him to the front page
   redirect('entry', 'location');
  }
}

Now here is the full code for the opml insertion:

Code:
function Opml()
{
  //check credentials
  $creds = $this->check_creds();
  $this->load->plugin(array('snagurls'));
  $user = $this->session->userdata('username');
  
   if($creds == TRUE)
   {
   //Upload file.
   $config['upload_path'] = './uploads/opml_files/';
   $config['allowed_types'] = 'xml';
   $config['max_size'] = '10000';
  
   $this->load->library('upload', $config);
  
   if( ! $this->upload->do_upload())
   {
$error = array('error' => $this->upload->display_errors());
$this->load->view('getstarted', $error);
   }
   else
   {
  //Read file contents.
  $file_info = array('upload_data' => $this->upload->data());
  
$opmlFile = './uploads/opml_files/' . $file_info['upload_data']['file_name'];
  
$fd = fopen($opmlFile, 'r');

$data = stream_get_contents($fd);

$thisXml = simplexml_load_string($data);
  
foreach($thisXml->body->outline as $item)
{
   foreach ($item->children() as $ol)//get the children of each main "outline" tag
   {
   $urlArray[] = "" . $ol['xmlUrl'] . "";
  }
}
if(file_exists($opmlFile)){unlink($opmlFile);}
foreach($urlArray as $url)
{
  $url = @SnagUrlCleaner($url);//clean supplied url
  $feedResult = $this->Add_Feed($url, $user);//returns true or false
  
  if($feedResult == false)//the url could not be found
  {
   $urlError[] = $url;
  }
}
if(isset($urlError))
{
  
  //var_dump($urlError);
  $data['urlError'] = $urlError;
  
  
  
  $this->load->view('gs_error', $data);
}
else
{
  //redirect user to the feed settings page.
}
  
   }

  
  
  
  
  }
  
}

Additionally I am getting another error in the OPML function when the view is shown:

Code:
A PHP Error was encountered

Severity: Notice

Message: Array to string conversion

Filename: controllers/getstarted.php

Line Number: 375

Not sure why I don't have the same problems with the first function.


Messages In This Thread
Controller variable not being passed to view - by El Forum - 07-19-2007, 11:22 PM
Controller variable not being passed to view - by El Forum - 07-19-2007, 11:51 PM
Controller variable not being passed to view - by El Forum - 07-20-2007, 02:07 AM
Controller variable not being passed to view - by El Forum - 07-20-2007, 09:14 AM
Controller variable not being passed to view - by El Forum - 07-20-2007, 09:22 AM
Controller variable not being passed to view - by El Forum - 07-20-2007, 01:27 PM

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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