[eluser]Burgestrand[/eluser]
--[ Question rewritten (using version 1.0, btw):
I’ve written a convenience method (helper):
Code:
/**
* Returnerar user-objektet, eller ett tomt objekt med samma attribut :o
*
* @return IR_Record models/Users.php OR config/schema.yml för att få listan över attributen
*/
function get_user()
{
if ( ! $user = authenticated(TRUE))
{
// Vi är inte inloggade, så skapa en ny “tom” användare
$users = new Users();
$user = $users->new_record(array_combine($users->list_fields(), array_fill(0, count($users->list_fields()), NULL)));
}
return $user;
}
The general thought is this: get_user() returns a record from the Users table. If the current visitor is logged in their record is returned, otherwise an empty (all columns set to NULL) is returned.
Is there a prettier way of constructing this record?
Secondly I'd like to make a suggestion in “base.php” and “base_php5.php” @ line 108:
from:
Code:
function list_fields($table)
{
$model =& IR_base::get_model($table);
[…]
to:
Code:
function list_fields($table = NULL)
{
(is_null($table) AND $table = $this->table);
$model =& IR_base::get_model($table);
[…]
This would allow one to ommit the table name (as I’ve done in my helper above).
Finally a quick question (possible bug) in ignitedquery.php in method delete (line 1751 -> 1759):
Code:
if(empty($this->q_where) && empty($this->like))
{
return false;
}
if($where != NULL)
{
$this->where($where);
}
Shouldn’t the latter if-statement preceed the former? Also, the method itself doesn’t take notice of the db_prefix set in the CI database config. I hit this problem when running the following code:
Code:
$posts = new Posts();
if ($post = $posts->where('author', $user->username)->find($id))
{
$post->delete($post); // this line *is* run, but nothing is deleted
}