Welcome Guest, Not a member yet? Register   Sign In
DataMapper ORM v1.8.0

[eluser]rei[/eluser]
hmm. so how can I only show the parent only once? because It really keeps repeating each and everytime Im showing the child.

If I use lazy loading It works fine, but it is slow.



and last question, I found a tutorial on datamapper - http://komunitasweb.com/2009/04/codeigni...atamapper/

He was making datamapper calls in the VIEW, like this one:

Code:
<?php foreach($student_list as $student): ?>
<?php $student->course->get()->order_by('name'); ?>
<?php $ctr++ ?>

Is it bad practice to do something like that in the view?

Thanks in advance and I'm looking forward for ur awesome 2.0 Wink


[eluser]WanWizard[/eluser]
The same as you would do with any normal JOIN, it's not related to datamapper. Use a flag to keep track of the parent.

Code:
$user = '';

foreach ($u->get_all_posts() as $userpost)
{
    if ($user != $userpost->username)
    {
        // new user, deal with it
        
        // store the user to prevent dealing with duplicates
        $user = $userpost->username;
     }

     // deal with the child info here
}

[eluser]rei[/eluser]
I just thought there is a more convenient way to do that.hehe.Like in other PHP active record they do it like:

Code:
foreach($users as $user){
foreach($user->posts as $post){
   echo $post->title;
}
}

I hope it can be done like that in 2.0 because it will be very awesome.

Nwei sir thanks sir for your help and thanks for your awesome datamapper ORM Wink

[eluser]WanWizard[/eluser]
That is not possible as the result of the query is "included", not distributed back to 'posts' objects.

It is on the roadmap for 2.0, but that will still have the include methods, as instantiating all these new objects is very memory and time intensive (on my development machine it takes about 20ms to instantiate a new object, you don't want to do that with a 1000 row result...).

2.0 works "just in time", i.e. it keeps the data internally in an optimal structure, and will only instantiate an object when one is requested.

[eluser]Netstrike[/eluser]
I have a problem when i load a datamapper model in a controller...
I use: Codeigniter+hmvc+template+datamapper

Controller (login.php):
Code:
class Login extends MY_Controller {

public function __construct()
{
  parent::__construct();
}
/*-------------------------------------------------------------------------------*/
public function index()
{
  $this->login();
}
/*-------------------------------------------------------------------------------*/
public function login()
{
  $this->template->write_view('middle', 'login/login_view');
  $this->template->render();
}
/*-------------------------------------------------------------------------------*/
public function check()
{
  $k = new User();
  
  $this->template->write_view('middle', 'login/login_view');
  $this->template->render();
}
/*-------------------------------------------------------------------------------*/
}

MY_Controller (MY_Controller.php):
Code:
class MY_Controller extends MX_Controller
{
public $data;

public function __construct()
{
  parent::__construct();
  $this->benchmark->mark('start');
  
  $this->form_validation->set_error_delimiters('<div class="message warning">', '</div>');
  
  $this->template->set_template('login');
  $this->template->write_view('top',  'top_view');
  $this->template->write_view('bottom',  'bottom_view');
  
  if (ENVIRONMENT == 'development')
  {
   $this->load->library('profiler');
   $this->output->enable_profiler(TRUE,FALSE);
  }
}
}

Model (User.php):
Code:
class User extends Datamapper {
/*-------------------------------------------------------------------------------*/
var $table = 'users';
/*-------------------------------------------------------------------------------*/
function __construct($id = NULL)
{
  parent::__construct($id);
}
/*-------------------------------------------------------------------------------*/
}

View (login_view.php):
Code:
<fieldset class="login-fieldset">
  <legend class="login-legend">Login</legend>
  &lt;form name="login" method="post" action="&lt;?php echo base_url(); ?&gt;login/check" enctype="application/x-www-form-urlencoded"&gt;
    <section>
      <label>Username</label> &lt;input type="text" class="input" name="username" value="" size="25" /&gt;
      <div>/div>
    </section>
    <section>
      <label>Password</label> &lt;input type="password" class="input" name="password" value="" size="25" /&gt;
      <div>/div>
    </section>
    <section>
      &lt;input class="form-button" value="Accedi" /&gt;
      <div class="lost"><a href="&lt;?php echo base_url(); ?&gt;login/lost/password">Password persa?</a></div>
    </section>
  &lt;/form&gt;
</fieldset>

When i try to load a propety login() no problem, when i try to load check() i found this error in the error.log of apache:
[Tue Aug 28 13:51:36 2012] [error] [client 127.0.0.1] PHP Fatal error: Call to a member function base_url() on a non-object in C:\\Users\\netstrike\\Desktop\\UniServer\\www\\Project\\system\\codeigniter\\helpers\\url_helper.php on line 67, referer: http://localhost/Project/login/check

I spending 2days to find the problem...
Thanks
Ettore

[eluser]WanWizard[/eluser]
I wouldn't know.

base_url() is a method of the Config class. The helper does
Code:
function base_url($uri = '')
{
$CI =& get_instance();
return $CI->config->base_url($uri);
}

Which is pretty standard CI code. Datamapper doesn't do anything with Config, so I doubt it's responsible for what is going on in your setup.

[eluser]Netstrike[/eluser]
I know it... i try to ri-create the system base code...

Thanks
Ettore

[eluser]Netstrike[/eluser]
I found the problem.... The "user" table in db have a column called "config" ...
Renamed this column, all work well.

Ettore

[eluser]coldscooter[/eluser]
I am looking into using the HMVC library for Codeigniter. Are there any compatibility issues with Datamapper ORM to be aware of?


[eluser]teomor[/eluser]
Anyone know how to fix the "Could not find the language line" errors in the log files?




Theme © iAndrew 2016 - Forum software by © MyBB