node_load($nid) gives me a fatal error in Drupal 7 - drupal-7

Pretty new to drupal 7 and a lot has changed. How can I simply load a node and print it out? I am using the following but the function node_load gives me: PHP Fatal error: Call to undefined function node_load()
$node = node_load(15);
echo '<pre>' . print_r($node,1) . '</pre>';

it sounds like it cant find the function node_load - which i can imagine only happening if you were trying to do this outside of the drupal framework? e.g. on a PHP page youve simply added into the webspace?
contents of file:
<?php
node_load(1);
make sure you have the node_load inside a drupal module you have created, and when its responding to a hook ( e.g. hook_view )
sites > all > modules > yourmodule
yourmodule.module
yourmodule_view($node, $view_mode){
node_load(1);
}

Related

WAMP doesn't refresh files

I've been working with WAMP for 2 years now and it's the first time I got this problem. I created a new website base with Symfony, and now I'm adding some files to it in Windows (by creating a bundle in a console) but it doesn't appear in the browser in localhost even I refresh it, so when I go in /web, I got those errors like these :
( ! ) Fatal error: Uncaught Error: Class 'SNS\PlatformBundle\SNSPlatformBundle' not found in D:\wamp\www\sns_symfony\sns_symfony\app\AppKernel.php on line 20
( ! ) Error: Class 'SNS\PlatformBundle\SNSPlatformBundle' not found in D:\wamp\www\sns_symfony\sns_symfony\app\AppKernel.php on line 20
Call Stack
# Time Memory Function Location
1 0.0010 385736 {main}( ) ...\app.php:0
2 0.0070 418000 AppKernel->handle( ) ...\app.php:19
3 0.0070 418000 AppKernel->boot( ) ...\Kernel.php:195
4 0.0070 418000 AppKernel->initializeBundles( ) ...\Kernel.php:132
5 0.0070 417952 AppKernel->registerBundles( ) ...\Kernel.php:492
Can someone help me please ? ^^'
I'll explain myself more. I used the bundle generator of Symfony so I dind't write anything, juste used the console. By the way there is some folders that WAMP can't see (I don't see them in the browser in localhost) and the file he's looking for are in those folders he can't see. There is the problem.
First of all, double check if the bundle really exists on your hard drive. You're on Windows, so just go to D:\wamp\www\sns_symfony\sns_symfony\src and check if there's a PlatformBundle\SNSPlatformBundle.php in your src dir. If not - now you know the generator didn't generate anything. Maybe accidentally aborted?
Then check if you have right PSR-0 or PSR-4 (most likely ) namespace in your composer.json file. You can run php composer validate to see warnings.
And as the last step run composer dump-autoload which updates the autoload file
Finally I found the solution after hours of deeps researches. Here it is :
Create the bundle
Edit your app/config/config.yml file like (add templating: engines ['twig'] in framework:)
framework:
templating:
engines: ['twig']
Thanks for help people ! :D
SOLVED !

CakePHP HTML Helper not working with Images

I have been developing a website in CakePHP 2.5.6 and have suddenly had an issue where when using $this->Html->Image(''); the image wont display on the page and I get this error if I go to the Image URL Directly:
Missing Controller
Error: ImgController could not be found.
Error: Create the class ImgController below in file: app/Controller/ImgController.php
<?php
class ImgController extends AppController {
}
Notice: If you want to customize this error message, create app/View/Errors/missing_controller.ctp
As I haven't been using CakePHP for long im not sure where to start with resolving this, its never done this before to me.
Any help would be appreciated,
Steve
EDIT:
The example I have been using is this:
<?php echo $this->Html->image('cake.power.gif');?>
it returns the following:
<img src="/trunk/img/cake.power.gif" alt="" />
I have checked and the image does exist on my server in the directory app/webroot/img/cake.power.gif

CakePHP Sending Files

I am trying to render images/pdfs that exist outside of my webroot. So this is what I'm doing in my controller to Send the File - as described here. But I'm getting a Fatal Error. Any ideas why and how to fix this? I'm running CakePHP 2.4.5.
$this->autoRender = false;
$path = '/path/to/valid/file.pdf';
$this->response->file($path);
return $this->response;
Fatal error: Call to undefined method Folder::slashTerm()
Stack trace:
{main}() /Path/To/My/htdocs/mysite/app/webroot/index.php:0
Dispatcher->dispatch() /Path/To/My/htdocs/mysite/app/webroot/index.php:96
Dispatcher->_invoke() /Path/To/My/htdocs/mysite/lib/Cake/Routing/Dispatcher.php:160
Controller->invokeAction() /Path/To/My/htdocs/mysite/lib/Cake/Routing/Dispatcher.php:185
ReflectionMethod->invokeArgs() /Path/To/My/htdocs/mysite/lib/Cake/Controller/Controller.php:490
PagesController->load_media() /Path/To/My/htdocs/mysite/lib/Cake/Controller/Controller.php:490
CakeResponse->file() /Path/To/My/htdocs/mysite/app/Controller/PagesController.php:227
File->__construct() /Path/To/My/htdocs/mysite/lib/Cake/Network/CakeResponse.php:1265
File->pwd() /Path/To/My/htdocs/mysite/lib/Cake/Utility/File.php:91
Problem solved. I had a Plugin that had a class Folder that was taking this over.

Parse error: syntax error, unexpected 'image' (T_STRING) in eval line

I`m trying to create a page that read the metadata of an image and allow user to edit it and save it to the same image.
After searching the internet I have found exiftool as the solution but I can make it work only as a command line not as a library in the page.
I have this code:
eval('$metadata=' . exiftool.exe -php -q $imagePath);
foreach ($metadata[0] as $key => $value) {
if ($metadata[0][$key]!=$_POST[$key]){
if ($_POST[$key]=="") $_POST[$key]=" "; //if metadata is not set, than create an empty metadata
eval('$metadata=' . exiftool.exe "-$key=$_POST[$key]" $imagePath);
}
}
and I`m getting this error:
Parse error: syntax error, unexpected 'image' (T_STRING) in E:\xampp\htdocs\imgdata\index.php(30) : eval()'d code on line 1
I tried to replace the ` with other like " and ' but no luck.
What do I miss?
Any better idea on how to do it?
Thanks
I had the same problem, but using Centos OS, and found a solution here:
'command not found' error when using subprocess in apache
Might not work for Windows but worth a look. Basically the answer suggests specifying the full exiftool path rather than simply exiftool.exe.
If that doesn't help then have a look for errors in the Apache Error Log File.

CakePHP "Warning: Cache not configured properly"

I am using CakePHP and getting the following error
Warning: Cache not configured properly. Please check Cache::config(); in APP/config/core.php in D:\PHP-SERVER\cheesecake\cake\libs\configure.php on line 663
Notice: Undefined variable: Route in D:\PHP-SERVER\cheesecake\app\config\routes.php on line 38
Fatal error: Call to a member function connect() on a non-object in D:\PHP-SERVER\cheesecake\app\config\routes.php on line 38
Any problem in the settings?
Which CakePHP version are you using?
The fatal error looks like a typo. Open the file D:\PHP-SERVER\cheesecake\app\config\routes.php and check what there is written on line 38. It looks like there is a letter missing.
It should be something along the lines of
Router::connect(...[whatever your route settings are]...);
and I guess in your file it says (note the missing r in Router)
Route::connect(...);
Did you do what the other error message said? Check the Cache::config call in app/config/core.php. You seem to have not properly set your cache configuration.
The default call looks like
Cache::config('default', array('engine' => 'File'));
If you changed that post the code-piece to figure out if something is wrong..

Resources