Forum

Thread tagged as: Problem, Docs

Trying to duplicate Portfolio with Categories/Two page list and detail with URL...

Hello,

As the title states, I'm still learning Perch so I'm trying to duplicate the pages from the Portfolio with Categories/Two Page List and Detail tutorials but I'm stuck on the URL rewrite part.

Currently, the Two Page List and Detail pages work perfectly if I link to /detail.php?s=item-slug-here from the List page. However, if I try to link to /detail/item-slug-here the custom content block on the Detail page will no longer load.

My code is near exact recreations of the tutorial material...

portfolio.php contains....

<?php

    perch_content_create('Portfolio', array(
      'template'   => 'portfolio_item.html',
      'multiple'    => true,
      'edit-mode' => 'listdetail',
    ));

    perch_content_custom('Portfolio', array(
      'template' => 'portfolio_listing.html',
    ));

    ?>

detail.php

<?php

        perch_content_custom('Portfolio', array(
          'page' => '/portfolio.php',
          'template' => 'portfolio_item.html',
          'filter' => 'slug',
          'match' => 'eq',
          'value' => perch_get('s'),
          'count' => 1,
        ));
    ?>

portfolio_listing.html and portfolio.item.html are also replicas of the tutorial material and thus far function as expected within the admin area and when viewed on a non-pretty URL.

.htaccess looks like:

<IfModule mod_rewrite.c> 
RewriteEngine on

RewriteRule ^detail/([a-zA-Z0-9-]+)$ /detail.php?s=$1 [L]
RewriteRule ^category/([a-zA-Z0-9-/]+)$ /category.php?cat=$1 [L]

# Redirect to PHP if it exists.
# e.g. example.com/foo will display the contents of example.com/foo.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f 
RewriteRule ^(.+)$ $1.php [L,QSA]

</IfModule>

I've also tested that the mod_rewrite module is working and my .htaccess file is accessible (the last rule is currently working and I can easily do simple URL rewrites and redirects) so unless I'm missing something that should not be the problem.

Finally, if it helps, I'm working locally on MacOS apache and my diagnostics report is as follows:

Perch: 2.8.6, PHP: 5.4.30, MySQL: mysqlnd 5.0.10 - 20111026 - $Id: c85105d7c6f7d70d609bb4c000257868a40840ab $, with PDO Server OS: Darwin, apache2handler Installed apps: content (2.8.6), assets (2.8.6), categories (2.8.6) App runtimes: <?php $apps_list = array( 'content', 'categories', ); PERCH_LOGINPATH: /perch PERCH_PATH: /Users/jennifer/Sites/jennifercodes/perch PERCH_CORE: /Users/jennifer/Sites/jennifercodes/perch/core PERCH_RESFILEPATH: /Users/jennifer/Sites/jennifercodes/perch/resources Image manipulation: GD PHP limits: Max upload 500M, Max POST 500M, Memory: 128M, Total max file upload: 128M Resource folder writeable: Yes HTTP_HOST: jennifercodes.dev DOCUMENT_ROOT: /Users/jennifer/Sites/jennifercodes/ REQUEST_URI: /perch/core/settings/diagnostics/ SCRIPT_NAME: /perch/core/settings/diagnostics/index.php

Please help me because I'm really at a loss for why this won't work.

Jennifer Scroggins

Jennifer Scroggins 1 points

  • 6 years ago

I've continued on with the Portfolio with Categories video-tutorial and I'm having the same difficulty with the categories URL rewrite... /category.php?cat=skills/sketch-adobecs/ works fine, but /category/skills/sketch-adobecs/ does not pull up the corresponding portfolio items.

I don't understand WHY but it appears as if the slug ID and the cat ID are not being passed.

Drew McLellan

Drew McLellan 2638 points
Perch Support

Do you have any rewrite rules working?

These are working...

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f 
RewriteRule ^(.+)$ $1.php [L,QSA]

and if I do something silly like

RewriteRule shazaaam.html example.php

it totally works.

What is interesting, is that if I remove ALL content from my .htaccess file, I can still access example.php by directing my browser to /example.... portfolio.php from /portfolio

Additionally, if I visit /detail/test-item-1 detail.php does pull up in the browser sans the portfolio_item content (just as it would with the rewrite rules in place in .htaccess).

Any idea what is going on here? I'm stumped.

RewriteRule shazaaam.html example.php does NOT still work if I remove it from .htaccess - so I'm taking that as evidence that apache is at least using my .htaccess file.

Drew McLellan

Drew McLellan 2638 points
Perch Support

Are your detail.php and category.php files in the root of the site?

They are.

If it helps... this is how I have my server set up.

Apache root is pointing to:

/Users/myusername/Sites/

within that folder are two different Perch sites that I'm tinkering with... so I have

/Users/myusername/Sites/site-1

/Users/myusername/Sites/site-2

In site-2 I'm trying to build something similar to the list/detail + Portfolio w/categories tutorials so I've been following them as a learning experience.

So, I've got my .htaccess file located in /Users/myusername/Sites/site-2/ along with detail.php portfolio.php category.php etc.

Is the problem that I have two perch installs within /Sites?

Drew McLellan

Drew McLellan 2638 points
Perch Support

Ok, so they're not in the root of the site - they're in a subfolder, right?

/detail.php is actually /site-2/detail.php ?

I guess that would be correct, yes.

So I changed my rewrite rules to:

RewriteRule ^/detail/([a-zA-Z0-9-/]+)$ /site-2/detail.php?s=$1 [L]
RewriteRule ^/category/([a-zA-Z0-9-/]+)$ /site-2/category.php?cat=$1 [L]

And it still doesn't work.

Forgot to mention - I also have virtual hosts set up for each perch site...

httpd-vhosts.conf contains:

<VirtualHost *:80>
    DocumentRoot /Library/WebServer/Documents
</VirtualHost>

<VirtualHost *:80>
    DocumentRoot "/Users/myusername/Sites/site-1/"
    ServerName site-1.dev
    <Directory "/Users/myusername/Sites/site-1/">
      Order allow,deny
      Allow from all
    </Directory>
</VirtualHost>

<VirtualHost *:80>
    DocumentRoot "/Users/myusername/Sites/site-2/"
    ServerName site-2.dev
    <Directory "/Users/myusername/Sites/site-2/">
      AllowOverride All
      Order allow,deny
      Allow from all
    </Directory>
</VirtualHost>

I'm probably making some n00b mistake somewhere in all this but I can't suss out what it is.

Drew McLellan

Drew McLellan 2638 points
Perch Support

Shouldn't that be:

RewriteRule ^site-2/detail/([a-zA-Z0-9-/]+)$ /site-2/detail.php?s=$1 [L]

That does not work either.... I've run this problem by a couple of the devs I work with and they're stumped too.

The best guess we can come up with at this point is that perhaps the slug is not getting passed to the perch_content_custom filter located in detail.php. When I point my browser at the 'prettified' url, detail.php does load, the problem is that the content that would be pulled in by the perch_content_custom tag is just not there.

Thoughts?

I even when into httpd.conf and httpd-vhosts.conf and reset my server root to /Users/myusername/Sites/site-2 ... still doesn't work.

Drew McLellan

Drew McLellan 2638 points
Perch Support

Are you saying that the rewrite is working? I thought the issue was that the rewrite wasn't working.

Well... it appears that the rewrite is working, but the content is not loading as in the tutorial.

I'm really sorry I was not more clear... I am new to apache rewrites so it has been difficult for me to determine where this is breaking.

Drew McLellan

Drew McLellan 2638 points
Perch Support

Can you add debug to your page and let me know what it outputs?

https://docs.grabaperch.com/docs/installing-perch/configuration/debug/

From /detail/test-item

Debug Message
SELECT * FROM perch2_pages WHERE pagePath='/detail.php' LIMIT 1
Using template: /templates/pages/attributes/default.html
Using sub-template: /templates/pages/attributes/seo.html
SELECT * FROM perch2_pages WHERE pageNew=0 AND pageHidden=0 AND pageDepth >=0 AND pageDepth<=2 ORDER BY pageTreePosition ASC
SELECT pageTreePosition FROM perch2_pages WHERE pagePath='/detail.php' LIMIT 1
Using template: /templates/navigation/item.html
SELECT regionID, regionTemplate, regionPage, regionRev AS rev FROM perch2_content_regions WHERE regionKey='Portfolio' AND (regionPage='/portfolio.php' OR regionPage='*')
SELECT * FROM ( SELECT idx.itemID, c.regionID, idx.pageID, c.itemJSON, idx2.indexValue as sortval FROM perch2_content_index idx JOIN perch2_content_items c ON idx.itemID=c.itemID AND idx.itemRev=c.itemRev AND idx.regionID=c.regionID JOIN perch2_content_index idx2 ON idx.itemID=idx2.itemID AND idx.itemRev=idx2.itemRev AND idx2.indexKey='_order' WHERE ((idx.regionID=13 AND idx.itemRev=8)) AND ((idx.indexKey='slug' AND idx.indexValue='')) AND idx.itemID=idx2.itemID AND idx.itemRev=idx2.itemRev ) as tbl GROUP BY itemID ORDER BY sortval ASC LIMIT 0, 1
Using template: /templates/content/portfolio_item.html
Drew McLellan

Drew McLellan 2638 points
Perch Support

Clearly no slug coming through there. Can you show me the code on your page where you're filtering with the slug?

perch_content_custom is directly from the tutorial... here's the entire detail.php page:

<?php include('perch/runtime.php'); ?>
<!doctype html>
<html lang="en">
<head>
    <meta charset="utf-8" />
    <title><?php perch_pages_title(); ?></title>
    <?php perch_page_attributes(); ?>
    <?php perch_get_css(); ?>
</head>
<body>
<!-- detail.php -->
    <?php perch_pages_navigation(array('levels'=>2)); ?>

    <?php
        perch_content_custom('Portfolio', array(
          'page' => '/portfolio.php',
          'template' => 'portfolio_item.html',
          'filter' => 'slug',
          'match' => 'eq',
          'value' => perch_get('s'),
          'count' => 1,
        ));
    ?>
<?php PerchUtil::output_debug(); ?>
    <?php perch_get_javascript(); ?>
</body>
</html>

portfolio_listing.html looks like:

<perch:before>
<ul>
</perch:before>

<li>
    <a href="detail/<perch:content id="slug" for="title" type="slug" />">
        <img src="<perch:content id="listimage" type="image" label="Image for listing page" width="300" height="200" crop="true" />" alt="<perch:content id="title" type="text" label="Title" required="true" title="true" />" />
        <h2><perch:content id="title" type="text" label="Title" required="true" title="true"/></h2>
    </a>
</li>

<perch:after>
</ul>
</perch:after>
Drew McLellan

Drew McLellan 2638 points
Perch Support

Can you add this to the page and let me know what it outputs?

<?php
    print_r($_GET);
?>