Welcome Guest, Not a member yet? Register   Sign In
DMZ Problem
#11

[eluser]WanWizard[/eluser]
Your portals table doesn't contain the foreign key to pages (page_id), so it can't make the link between the two.
#12

[eluser]7amza[/eluser]
portals table doesn't contain the forein key to categories(category_id) and it works fine so can you make this point clear please?
#13

[eluser]7amza[/eluser]
i added the FK in portable tables but still the problem exist
Quote:DataMapper Error: 'page' is not a valid parent relationship for Portal. Are your relationships configured correctly?
#14

[eluser]WanWizard[/eluser]
Sorry, didn't notice that you were trying to get from page to portal, that should indeed work without the FK.

Ran a test using a fresh CI installation, copied the Datamapper library and the helpers in, created a test database with your tables, and created the models just are you posted them.
I've added this method to Welcome.php:
Code:
function test()
{
    $this->load->database();

    $page = new Page();
    $portal = new Portal();
    $category = new Category();

    var_dump($category->get_where(array('portal_id'=>'2'))->to_array());
    var_dump($category->portal->get()->to_array());

    var_dump($page->get_where(array('portal_id'=>'2'))->to_array());
    var_dump($page->portal->get()->to_array());
}

Calling this method produces:

Code:
array
  'id' => int 6
  'portal_id' => string '2' (length=1)
  'title' => string 'My Category' (length=11)
  'description' => string 'cat desc' (length=8)
  'slug' => string '/slug/cat' (length=9)
  'created' => string '2010-08-01 11:25:09' (length=19)
  'updated' => string '2010-08-01 11:25:09' (length=19)

array
  'id' => int 2
  'title' => string 'My Portal' (length=9)
  'created' => string '2010-08-01 11:25:09' (length=19)
  'updated' => string '2010-08-01 11:25:09' (length=19)
  'slug' => string '/slug' (length=5)

array
  'id' => int 6
  'portal_id' => string '2' (length=1)
  'title' => string 'My Page' (length=7)
  'content' => string 'Content here' (length=12)
  'slug' => string '/slug/page' (length=10)
  'created' => string '2010-08-01 11:25:09' (length=19)
  'updated' => string '2010-08-01 11:25:09' (length=19)

array
  'id' => int 2
  'title' => string 'My Portal' (length=9)
  'created' => string '2010-08-01 11:25:09' (length=19)
  'updated' => string '2010-08-01 11:25:09' (length=19)
  'slug' => string '/slug' (length=5)

Conclusion: works as advertised. So your error is elsewhere.

You're not having a library or a controller called 'page' do you, which causes $this->page to exist, and the model not to be loaded.
#15

[eluser]7amza[/eluser]
wan thanks for help ,
i sent you the app folder so you can see the problem because already the i use a fresh CI installation.
#16

[eluser]WanWizard[/eluser]
I hope I don't offend you by replying in public, but I think others can learn from this too.

Apart from the issue at hand, one tip up front: do NOT use CAPITALS in your file or directory names. You must be using Windows to develop.

It took me 15 minutes to figure out why I was getting 404 errors, which was because of your modules starting with a capital letter.
Not done, and a disaster waiting to happen if you have to move to a hoster that runs on Linux or Unix.

Tip number two: always read the documentation before you start using something. In this case, datamapper creates a production cache as soon as you define a location in the config file. The cache contains information about your tables and your models. Once the cache exists, the model itself will no longer be used. Always disable the production cache while developing.

Final tip: see tip two. In this case, try to understand how things work before you start to use them, otherwise the strangest things happen.

Your code:
Code:
$portal = new portal(2);
$data['categories'] = $portal->category->get();
$page  = new page();
$data['pages'] = $page->get();

You're dealing with objects here, so you don't have to assign them to variables, that will only create copies. Also, if you need categories and pages belonging to a portal ID, retrieve them from the portal object.

Code:
// create the portal object
$data['portal'] = new portal(2);
// fetch the categories
$data['portal']->category->get();
// fetch the pages
$data['portal']->page->get();

Remember, you have an object hierarchy loaded ( portal->category and portal->page ).

Then, in your view you do:

Code:
<?php foreach($categories AS $cat):?>
<li> » &lt;?=anchor($cat->category->slug.'/Services/'.$cat->slug,$cat->title);?&gt;</li>
&lt;?php endforeach;?&gt;

&lt;?php foreach($pages AS $pg):?&gt;
<li> » &lt;?=anchor($pg->page->slug.'/Documentation/'.$pg->slug,$pg->title);?&gt;</li>
&lt;?php endforeach;?&gt;

You should do (using the code above):

Code:
&lt;?php foreach($portal->category AS $cat):?&gt;
<li> » &lt;?=anchor($cat->slug.'/Services/'.$portal->slug,$portal->title);?&gt;</li>
&lt;?php endforeach;?&gt;

&lt;?php foreach($portal->page AS $pg):?&gt;
<li> » &lt;?=anchor($pg->slug.'/Documentation/'.$portal->slug,$portal->title);?&gt;</li>
&lt;?php endforeach;?&gt;

Hope this helps you get going...
#17

[eluser]7amza[/eluser]
Wan you're the best ,
it works fine , I can not find words to express my thanks to you .
#18

[eluser]7amza[/eluser]
hey guys ,
i want ask you about two things :
is there anymethod wich return The number of rows returned by the query? like num_rows ?
i didn't understood the validate functio in the library so can anyone make it clear for me please?
#19

[eluser]7amza[/eluser]
i understood them ^^
thanks for help




Theme © iAndrew 2016 - Forum software by © MyBB