Welcome Guest, Not a member yet? Register   Sign In
[Deprecated] DMZ 1.5.3 (DataMapper OverZealous Edition)

[eluser]Jeffrey Lasut[/eluser]
hehe Smile I caught it just in the nick of time. To bad about the rap, I would enjoyed reading it.

English is not my native language, so expect some typos in the near future Wink

[eluser]bEz[/eluser]
[quote author="OverZealous" date="1255006305"]... I was going to write a rap about D-M-Z's complex-i-ty.

:lol:[/quote]
Wow!

Phil's extending his range of abilities to entertainment now.
Quote:I hope you perform better than "Calhoun Tubbs" from In Living Color"

[eluser]tomdelonge[/eluser]
So I've got a simple little store I'm making. I want categories to be able to have categories. I really feel like this code is too cluttered and I'm not sure if It's the best way to do it.

So the url would look like this:

categories/view/5

10 products at a time should show up on a page. Here's my questions:
1) Should I clone an object (or even create a new one) just to find the current category? What's a better way?
2) Am I even getting the categories in the best ways (best sql queries?) I'm not going to be caching pages, so I want the best possible queries.
3) with the pagination, do I really need to do a whole other query just to find if another page is possible?

Basically, give me any suggestions that you have. Thanks. (This is my first project with dmz, if you can't tell from my code).

each product has_one category
each category has_many products

Code:
function view($id = NULL)
    {
        $array = $this->uri->uri_to_assoc(2);
        $page = element('page', $array);
        if ( ! $page)
        $page = 1;
        if( ! $id)
        {
            show_404();
        }
        else
        {
            $c = new Category();
            $c->get_by_id($id);
            
            if ( ! $c->exists())
            {
                show_404();
            }
            else
            {
                //the category exists
                //if it's the lowest one (has no children)
                //then find the products that go to it.
                $c = new Category();
                $current = $c->get_clone();
                //find all categories that have parent of $id
                $c->where('parent', $id)->get();
                if ( ! $c->exists())
                {
                    //no more children; display the products
                    $p = new Product();
                    $c = new Category();
                    $c->get_by_id($id);
                    
                    $limit = 10;
                    $offset = ($page * $limit) - $limit;
                    $c->product->get($limit, $offset);
        
                    $current->get_by_id($id);
                    $data['products'] = $c->product->all_to_array();
                    $data['current'] = $current->name;
                    $data['c'] = $c->all_to_array();
                    
                    $limit = 10;
                    $offset = (($page + 1) * $limit) - $limit;
                    $c->product->get($limit, $offset);
                    $data['next_page'] = FALSE;
                    if ($c->product->exists())
                    {
                        $data['next_page'] = $page + 1;
                    }
                    
                    $this->load->view('shopping/categories/view', $data);
                }
                else
                {
                
                }
            }
        }
    }

[eluser]Monotoba[/eluser]
Hi folks, I'm needing a little help. I am trying to use DMZ with a CI-CMS. My issue is that CI-CMS uses a table prefix of 'ci_' and I would like to use table prefixes in my module that is using DMZ. If I set prefixes in the config.php file the DMZ related queries refere to the same tables in two different ways. First, using the DMZ prefix and then using the DMZ and CI prefix (concantinated) as in 'ci_ci_<tablename>'. Is there anyway to get DMZ or DataMapper to work with CI table prefixes?

Thanks for the help

[eluser]OverZealous[/eluser]
@Monotoba

Please read the documentation.

[eluser]storkontheroof[/eluser]
Hi,

This is my first project using DMZ and i must say i really like it.
Thanks for this product!!

I've got a question about saving an object though.
Note: I have set $db['db_debug'] to FALSE.

When my object validates, but there is some sort of DB error, DMZ returns TRUE even when the the transaction status ($this->db>trans_status()) is FALSE.

I noticed the following lines in the save method of the datamapper library (around line 1003):
Code:
// Create new record
$this->db->insert($this->table, $data);

if( ! $this->_force_save_as_new)
{
    // Assign new ID
    $this->id = $this->db->insert_id();
}
                    }
$trans_complete_label[] = 'insert';

// Reset validated
$this->validated = FALSE;

$result[] = TRUE;

Why isn't the last line like this:
Code:
$result[] = $this->db->trans_status();


Am i misunderstanding something??

Hope to hear from you.

Regards,
Richard

[eluser]OverZealous[/eluser]
Hi storkontheroof,

It looks like that might make more sense, I'll have to look into it when I get more time.

However, DMZ handles validation almost exclusively within PHP (obviously, in real life, the DB needs to check as well). The result of save() and the related methods is more about whether or not the validation succeeded.

If your validation is configured correctly, it should be pretty rare that you have a DB error.

[eluser]storkontheroof[/eluser]
Hi Phil,

Thanks for your reply and you're right: with validation configured correctly, DB errors will be rare.

Regards,
Richard

[eluser]ennis[/eluser]
Hi guys, I have successfully used has_one and many now brilliant!

But i have run into a problem my clients_users works fint as in the users table is now related to the clients table vise versa though clients_users ( id, client_id , user_id )

I have dont the same for my tickets table and related them to clients since a client can have many tickets via the table clients_tickets(id,client_id,ticket_id)

all the clients users and tickets tables start with column id etc. as it says in the manuel

I get this error

DataMapper Error: 'client' is not a valid parent relationship for Ticket. Are your relationships configured correctly?

My model
Code:
class Client extends DataMapper {

    var $has_many = array(
        'ticket',
        'user',
        'relatedclient' => array(
            'class' => 'client',
            'other_field' => 'client'
        ),
        'client' => array(
            'other_field' => 'relatedclient'
        ),

    );
    
    function __construct($id = NULL)
    {
        parent::__construct($id);
    }

    function Client()
    {
        parent::DataMapper();
    }
}


any ideas?

[eluser]OverZealous[/eluser]
@ennis

See the documentation.




Theme © iAndrew 2016 - Forum software by © MyBB