[eluser]PoetaWD[/eluser]
Hey man....
Is there a way to use a custom field as the ID field ?
I mean... every table that datamapper will use must have a id field, is there a way to use a field with a diferent name, like: custom_id ?
I need this because I am using a already existing database that I cannot modify its structure....
[eluser]WanWizard[/eluser]
No, the use of 'id' as primary key is hardcoded in Datamapper. And in the current codebase it's virtually impossible to change that without a large rewrite of the code.
[eluser]coldscooter[/eluser]
How would i run an include_related() to include a related table but still return the row if there is no relating record in the related table?
[eluser]WanWizard[/eluser]
You can't. If you ask for included data, Datamapper runs an INNER JOIN, to make sure every parent has a child that can be included. There is currently no option to change that.
[eluser]Carmichael[/eluser]
library/auth
Code: /**
* login
*
* @access public
* @param string $username
* @param string $password
* @return bool
*/
public function login($username, $password)
{
// Create a new temporary user object
$user = new User();
if ($user->login($username, $password))
{
// Prepare session data
$userdata = array(
'user_id' => $user->id,
'username' => $user->username,
'activated' => $user->active === 1 ? TRUE : FALSE,
'logged_in' => TRUE
);
// Set sesssion data
$this->session->set_userdata($userdata);
$this->messages->set('success', 'login_success');
return TRUE;
}
else
{
$this->messages->set('error', 'login_failed');
return FALSE;
}
}
model/user
Code: /**
* login
*
* @param string $username
* @param string $password
* @return bool
*/
function login($username, $password)
{
$this->where('username', $username);
$this->where('password', self::_encrypt($password));
$this->get();
if ($this->exists())
{
$this->ip_address = $this->session->userdata('ip_address');
$this->last_login = time();
$this->save();
return TRUE;
}
}
error
Code: Fatal error: Call to a member function userdata() on a non-object in C:\wamp\www\codeigniter\application\models\User.php on line 68
Line 68
Code: $this->ip_address = $this->session->userdata('ip_address');
What am I doing wrong here?
[eluser]WanWizard[/eluser]
Assuming this is a Datamapper model, and not a CI model, you don't have access to the CI superobject via $this.
In Datamapper models you have to use the "library way":
Code: $CI =& get_instance();
$CI->session->userdata('ip_address');
[eluser]Tonko[/eluser]
Hello to all,
I am just a new user of DATAMAPPER and I would like to ask you if is posibble do this code in datamapper:
Code: $ordering = $this->db->select("article_ordering")
->from('pages')
->where('id', $page_id)
->get()->row()->article_ordering;
$query = $this->db->select("a.title AS articles_title, a.content AS articles_content, a.excerpt AS articles_excerpt, a.slug AS articles_slug,a.views AS articles_views, a.views AS articles_views,CONCAT(up.first_name, ' ', up.last_name) AS articles_author, DATE_FORMAT(a.created, '%T %d.%m.%Y') AS articles_created,
(SELECT IFNULL(ROUND(AVG(av.vote),1), 0) FROM articles_votes av WHERE a.id = av.article_id) AS articles_votes,(SELECT COUNT(ac.id) FROM articles_comments ac
WHERE a.id = ac.article_id) AS articles_totalcomments", FALSE)
->from('articles a')
->join('user_profiles up', 'a.author_id = up.user_id')
->where('page_id', $page_id)
->order_by("a.$ordering")
->limit($num, $offset)
->get();
Thank you,
Regards
[eluser]WanWizard[/eluser]
The first one can't, because Datamapper doesn't do rows. The get() returns an object, so you'll have to use $ordering->article_ordering to access that column value.
The second one is no problem, providing you have defined the correct relations (to create the join).
[eluser]pukrai[/eluser]
Hi there,
first of all: thanks for providing DataMapper, I really enjoy the functionality and your support.
Now I got a head-scratcher: I am currently writing an auth lib for myself and I am getting this error:
Code: ErrorException [ Fatal Error ]: Call to undefined method CI_DB_mysql_driver::dm_call_method()
FCPATH/application/libraries/datamapper.php [ 1113 ]
1108 register_shutdown_function(array($CI->db, 'close'));
1109 $CI->db->_has_shutdown_hook = TRUE;
1110 }
1111 // clone, so we don't create additional connections to the DB
1112 $this->db = clone($CI->db);
1113 $this->db->dm_call_method('_reset_select');
1114 }
1115 else
1116 {
1117 // connecting to a different database, so we *must* create additional copies.
1118 // It is up to the developer to close the connection!
I searched the web and the forums and the only thing I found was: Bootstrapper not included, but it is in my index.php:
Code: /* --------------------------------------------------------------------
* LOAD THE DATAMAPPER BOOTSTRAP FILE
* --------------------------------------------------------------------
*/
require_once APPPATH.'third_party/datamapper/bootstrap.php';
/*
* --------------------------------------------------------------------
* LOAD THE BOOTSTRAP FILE
* --------------------------------------------------------------------
*
* And away we go...
*
*/
require_once BASEPATH.'core/CodeIgniter.php';
I am not auto-loading any models.
I thought a moment if my php version does not support heredoc, but dismissed this though (running 5.3.10 on ubuntu) and still, I have no idea what the problem might be. Most of the time it plain works as it should, but right now, I am getting this error, always on the same controller function call. Disappointingly enough, I thought it was ion_auth interfering with datamapper, that's why I wrote my own auth lib working very closely with Datamapper ORM, but now that I switch from ion_auth to my library I am getting the same errors (not sure if at the same spot, it has been some time).
Any pointers? The third_party/datamapper/system/DB_driver.php is definitely loaded, since it throws errors when I change something in there.
Thanks in advance,
puk
[eluser]Tonko[/eluser]
[quote author="WanWizard" date="1347812714"]The first one can't, because Datamapper doesn't do rows. The get() returns an object, so you'll have to use $ordering->article_ordering to access that column value.
The second one is no problem, providing you have defined the correct relations (to create the join).[/quote]Thanks... Can you give some example how to do it?
|