CrashyBang Posted November 23, 2014 Share Posted November 23, 2014 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... Quote Link to comment Share on other sites More sharing options...
Frank_b Posted November 23, 2014 Share Posted November 23, 2014 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? Quote Link to comment Share on other sites More sharing options...
CrashyBang Posted November 24, 2014 Author Share Posted November 24, 2014 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. Quote Link to comment Share on other sites More sharing options...
QuickOldCar Posted November 29, 2014 Share Posted November 29, 2014 (edited) 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'];?> Edited November 29, 2014 by QuickOldCar Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.