elseif(isset($_POST['edit']))
{
$val = Validation::factory('noticia');
$val->set_message('required', 'O campo <strong>:label</strong> é necessário.');
$val->set_message('min_length', 'O campo <strong>:label</strong> tem que conter no mínimo <strong>:param:1</strong> caracteres.');
$val->set_message('max_length', 'O campo <strong>:label</strong> não pode conter mais que <strong>:param:1</strong> caracteres.');
$val->add_field('edit_id', 'ID', 'required');
$val->add_field('titulo', 'Titulo', 'required|min_length[3]|max_length[255]');
$val->add_field('pimg', 'Imagem principal', 'min_length[3]');
$val->add_field('descricao', 'Descrição', 'min_length[3]');
$val->add_field('texto', 'Texto', 'required|min_length[5]');
//$val->add_field('inhome', 'Mostrar na página principal', NULL);
// run validation on just post
if ($val->run())
{
$entry = Model_Noticias::find(Input::post('edit_id'));
$entry->username = Auth::get_screen_name();
$entry->titulo = Input::post('titulo');
$entry = Input::post('pimg');
if($img)
{
$arr = explode('/', $img);
$arr = array_reverse($arr);
$img = $arr[0];
}
$entry->pimg = $img;
$entry->descricao = Input::post('descricao');
$entry->msg = Input::post('texto');
$entry->inhome = Input::post('inhome');
$entry->save();
}
else
{
foreach($val->errors() as $error)
$data['errors'] .= $error.'<br />';
$data['isedit'] = true;
$data['edit'] = Model_Noticias::find(Input::post('edit_id'));
}
}
ErrorException [ Error ]: Call to a member function save() on a non-object 108 $entry->save();
Phil Foulston wrote on Friday 29th of July 2011:I thought you couldn't use Input::post('edit_id') in that way because the return value is mixed? Shouldn't it be $edit_id = Input::post('edit_id'); Then $entry = Model_Noticias::find($edit_id);
ErrorException [ Error ]: Call to a member function save() on a non-object
108 $entry->save();
$entry = Input::post('pimg');
Thus you're overwriting the $entry object you created with a posted value. Still that couldn't cause your error as it would have gotten you into problems way before when you use $entry as an object 6 lines below this quoted statement. Which makes me believe the error is either somewhere else or you edited the code before posting/after getting the error. It looks like you're new here. If you want to get involved, click one of these buttons!