Jump to content

Cockpit CMS Blog example not working


CrashyBang

Recommended Posts

I am working from Cockpit CMS and I am trying to create a blog using this tutorial.


Directory structure (simplified):



+blog
-index.php
+ views
-index.php
-article.php
-index.php
+partials
-constants.php
-top.php

blog/index:



<?php require_once("../partials/errorlogging.php"); ?>
<?php require_once("../partials/constants.php"); ?>
<?php require_once("../partials/top.php"); ?>

<?php

$app = new Lime\App();

// bind routes

$app->bind("/", function() use($app) {

$posts = collection('blog')->find(["public"=>true])->sort(["created"=>1])->toArray();

return $app->render('views/index.php', ['posts' => $posts]);
});


$app->bind("/article/:id", function($params) use($app) {

$post = collection('blog')->findOne(["_id"=>$params['id']]);

return $app->render('views/article.php', ['post' => $post]);
});

$app->run();

?>

<?php require_once("../partials/bottom.php"); ?>

blog/views/index.php:



<?php require_once("../../partials/errorlogging.php"); ?>
<?php require_once("../../partials/constants.php"); ?>
<?php require_once("../../partials/top.php"); ?>

<?php foreach ($posts as $post): ?>
<h2><a href="<?php $this->route('/article/'.$post['_id']);?>"><?php=$post['title'];?></a></h2>
<?php endforeach; ?>

<?php require_once("../../partials/bottom.php"); ?>

blog/views/article.php:



<?php require_once("../../partials/errorlogging.php"); ?>
<?php require_once("../../partials/constants.php"); ?>
<?php require_once("../../partials/top.php"); ?>

<h1><?php=$post['title'];?></h1>

<p>
<?php=$post['content'];?>
</p>

<?php require_once("../../partials/bottom.php"); ?>

Now at the moment if I go to domain.name/blog/ I receive this error:



{"type":64,"message":"require_once(): Failed opening required '..\/..\/partials\/errorlogging.php' (include_path='.:\/home\/codio\/.parts\/packages\/php5-apache2\/5.5.15\/lib\/php')","file":"\/home\/codio\/workspace\/blog\/views\/index.php","line":1}

However I know for a fact that it is not a problem with the require methods because if I run this code inblog/index.php:



<?php require_once("../../partials/errorlogging.php"); ?>
<?php require_once("../../partials/constants.php"); ?>
<?php require_once("../../partials/top.php"); ?>

<?php

$app = new Lime\App();

$app->bind("/", function() {
return "Hello World!";
});

$app->run();

?>

<?php require_once("../../partials/bottom.php"); ?>

There is absolutely no errors on the page or console, and "Hello World" is printed to the screen, so it is to do with the blog/index.php syntax but I have no idea where the problem is...


Link to comment
https://forums.phpfreaks.com/topic/292667-cockpit-cms-blog-example-not-working/
Share on other sites

so if you type in your browser: 

http://mydomain/blog

you do get an error, and if you type

http://mydomain/blog/index.php

everything is fine?

 

That is server behavior i think. Is there any .htaccess file somewhere in http://mydomain or in http://mydomaine/blog ?

 

If there is, what is the content of this file?

 

Is it your own server or computer or do you use a shared server from a host?

There is an .htaccess file in the blog folder with the following content:

 

<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteRule ^(.*)$ index.php/$1 [QSA,L]
</IfModule>

Both:  

http://mydomain/blog

and

http://mydomain/blog/index.php

return this error:

{"type":64,"message":"require_once(): Failed opening required '..\/..\/partials\/errorlogging.php' (include_path='.:\/home\/codio\/.parts\/packages\/php5-apache2\/5.5.15\/lib\/php')","file":"\/home\/codio\/workspace\/blog\/views\/index.php","line":1}

It is a Codio project so as far as I can tell it would be like my own server (not shared).

 

Cheers,

Otis.

Most likely a directory path issue, can try doing this before the require

 

dirname(__FILE__) ensures that the require_once function uses an absolute rather than relative path

 

Use the folder names

$directory_path = dirname(__FILE__) . DIRECTORY_SEPARATOR;
require_once($directory_path . "/folder_name/folder_name/partials/errorlogging.php");

echo these as well

<?php=$post['content'];?>

to

<?php echo $post['content'];?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.