Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to update a record using PHPActiveRecord and CodeIgniter?
    text
    copied!<p>Im breaking my head here. Hope you can see what's the error. I've installed PHPActiveRecord to CodeIgniter throught a spark and all works great except one thing. Let me show you some code.</p> <p>This is my problematic controller.</p> <p>Model <strong>Article.php</strong></p> <pre><code>&lt;?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); class Article extends ActiveRecord\Model { static $belongs_to = array( array('category'), array('user') ); public function updater($id, $new_info) { // look for the article $article = Article::find($id); // update modified fields $article-&gt;update_attributes($new_info); return true; } } </code></pre> <p>And this is the part where it shows me an error. Relevant code in Controller <strong>articles.php</strong></p> <pre><code> // if validation went ok, we capture the form data. $new_info = array( 'title' =&gt; $this-&gt;input-&gt;post('title'), 'text' =&gt; $this-&gt;input-&gt;post('text'), 'category_id' =&gt; $this-&gt;input-&gt;post('category_id'), ); // send the $data to the model if(Article::updater($id, $new_info) == TRUE) { $this-&gt;toolbox-&gt;flasher(array('code' =&gt; '1', 'txt' =&gt; "Article was updated successfully.")); } else { $this-&gt;toolbox-&gt;flasher(array('code' =&gt; '0', 'txt' =&gt; "Error. Article has not been updated.")); } // send back to articles dashboard and flash proper message redirect('articles'); </code></pre> <p>When i call Article::updater($id, $new_info), it display a big annoying error:</p> <p><strong>Fatal error:</strong> Call to a member function update_attributes() on a non-object</p> <p><strong>The weirdest thing, is that i have a controller called categories.php and model Categoy.php</strong> that has the same functionality (i copy pasted the categories functionality for the articles) and this time, doesn't work.</p> <p>I have different functions inside model Article.php and all of them work fine, im struggling with that Article::updater part.</p> <p>Does somebody know for a way to proper update a row? Im using as stated at docs in PHP AR site and it's giving me that error. Why it does say that is not an object? It's supposed to be an object when i do $article = Article::find($id).</p> <p>Maybe im not seeing something really easy. Too many hours in front of computer.</p> <p>Thanks amigos.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload