Add Canonical URL when Creating Page Programmatically

Permalink
I'm creating some pages programmatically with the following code, but I can't seem to find the correct reference for Canonical URL, or the page URL. I want to make it different than the title of the page.

Loader::model('collection_types');
$path = "/resources/newpage";
$newPage = Page::getByPath($path);
$data = array();
$data['cName'] = $title;
$data['cDescription'] = $title. " " .$date;
$data['cURL'] = $pageURL;
$ct = CollectionType::getByHandle('right_sidebar');
$newPage->add($ct, $data);


I thought it would be $data['cURL'] as shown above. But that doesn't work.

Any suggestions?

 
jordanlev replied on at Permalink Reply
jordanlev
I think you want 'cHandle' (note that this must be a relative URL, for example "/about/people", not "http://example.com/about/people")
Daac replied on at Permalink Reply
Daac
hi,

i setup a package with a template, blocks and a single page. everything works fine.

now i add the code above to the package controller, but i get an error.

Call to a member function getPackageID() on a non-object in F:\Server\xampp\htdocs\projekte\C5-Developer\concrete\models\page.php on line 1943

here is the code i add to the controller

Loader::model('collection_types');
      $path = "/";
      $pr = Page::getByPath($path);
      $data = array('cName'=>'Hallo Welt', 'cDescription'=>'Testet einfach drauf los', 'cHandle'=>'halle-welt');
      $ct = CollectionType::getByHandle('right_sidebar');
      $pr->add($ct, $data);


did i miss something?

thanks for your help
jordanlev replied on at Permalink Reply
jordanlev
I don't see anything strange in the specific code snippet you posted -- can you please post the entire contents of your package's controller.php file (might be easiest to ZIP it and post that as an attachment)? I think the problem might be somewhere else in the file.

Also, are you getting this error when you try to install the package, or some other time (like when a page is viewed or edited)?
Daac replied on at Permalink Reply 1 Attachment
Daac
hi,

here is the controller.php ...

I only get this error on this controller.php file.
everything else work fine...

i test the getPackageID inside the controller with
var_dump($pkgID);
var_dump($this->getPackageID);

and it returns NULL.

i think there is the problem
jordanlev replied on at Permalink Reply
jordanlev
I think the problem may be this line:
BlockType::installBlockTypeFromPackage('autonav', $pkg);


The autonav block is already installed as part of the core C5 system -- you cannot have another block with the same name.

Is this just for some custom template files? If so, you don't need to do anything in the install function -- as long as they're in the proper place ( YOURSITE/packages/henrich_parkett_pack/blocks/autonav/templates/ ).

Or did you create another block called "autonav"? If so, you need to rename it.
Daac replied on at Permalink Reply
Daac
hi,

the autonav is only for the custom template on a fresh installation of C5. I found the problem with the page installation. i forgot to install the page-type i want to use. but now i run into another problem.

mysql error: [1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'LIMIT 1' at line 1] in EXECUTE("select max(cDisplayOrder) from Pages where cParentID = LIMIT 1")


i love Concrete5 for this "learning by doing feature" ^^
jordanlev replied on at Permalink Reply
jordanlev
Where / when are you getting that error? Please post code.