After installing CakePHP successfully, on first time running, I'm getting these warnings at the bottom. How can I fix this.
Warning (2): Missing argument 1 for View::element(), called in /Users/michaelanywar/Sites/cakephp/app/View/Layouts/default.ctp on line 61 and defined [CORE/Cake/View/View.php, line 398]
Notice (8): Undefined variable: name [CORE/Cake/View/View.php, line 416]
Notice (8): Undefined variable: name [CORE/Cake/View/View.php, line 422]
Notice (1024): Element Not Found: Elements/.ctp [CORE/Cake/View/View.php, line 425]
My View/view.php lines from 398 to 427 look like this:
public function element($name, $data = array(), $options = array()) {
$file = $plugin = null;
if (isset($options['plugin'])) {
$name = Inflector::camelize($options['plugin']) . '.' . $name;
}
if (!isset($options['callbacks'])) {
$options['callbacks'] = false;
}
if (isset($options['cache'])) {
$contents = $this->_elementCache($name, $data, $options);
if ($contents !== false) {
return $contents;
}
}
$file = $this->_getElementFilename($name);
if ($file) {
return $this->_renderElement($file, $data, $options);
}
if (empty($options['ignoreMissing'])) {
list ($plugin, $name) = pluginSplit($name, true);
$name = str_replace('/', DS, $name);
$file = $plugin . 'Elements' . DS . $name . $this->ext;
trigger_error(__d('cake_dev', 'Element Not Found: %s', $file), E_USER_NOTICE);
}
}
If you look at your first warning/error message it should be clear what the issue is: "Warning (2): Missing argument 1 for View::element()".
Look on line 61 of your default layout View template (/app/View/Layouts/default.ctp). You obviously have a call to $this->element() that isn't passing a template name (hence Cake is looking for "Elements/.ctp").
Make sure you pass a template name to the element() method or remove it from your template. For example, if you want to include the template "View/Elements/site_header.ctp":-
echo $this->element('site_header');
The template just needs to exist in the 'View/Elements' folder. You don't need to pass the '.ctp' extension to the element() method, Cake assumes this.
Make sure you've read the docs on Elements.
Moving the default.ctp to View/Elements folder was the best thing and then calling it element('default');?>
I removed the default.ctp in the layout folder..
Related
I am trying to add a plugin in my wordpress site.But for one of the function i am getting this warning.this is the warning:
Warning: Use of undefined constant file_put_contents - assumed
'file_put_contents' (this will throw an Error in a future version of
PHP)
This is the function where i am getting this warning.It's for the second line i am getting the warning:
function qrs_create_css_file ($update) {
if (function_exists(file_put_contents)) {
$css_dir = plugin_dir_path( __FILE__ ) . '/quick-range-custom.css' ;
$filename = plugin_dir_path( __FILE__ );
if (is_writable($filename) && (!file_exists($css_dir) || !empty($update))) {
$data = qrs_generate_css();
file_put_contents($css_dir, $data, LOCK_EX);
}
}
else add_action('wp_head', 'qrs_head_css');
}
How can i resolve this warning?
Try:
if (function_exists('file_put_contents')) {
You are not using quotation around file_put_contents which led the system to assume that it is a constant.
This question already has answers here:
PHP - Failed to open stream : No such file or directory
(10 answers)
Closed 5 years ago.
I am just trying to make a simple PHP program that allows me to generate my page quickly.
I am completely new at PHP.. And I have no clue what I am doing.
/index.php
<?php
include "/base/startup.php";
echo "Test";
startPage("Home");
?>
I'm getting a 500 server error with this.. Please tell me what I'm doing wrong. Thank you.
/base/startup.php
$HOME = "/";
$SCRIPT = <<<EOD
EOD;
$IMPORTS = array(
"/scripts/script.js"
);
$STYLES = array(
"/styles/style.css"
);
function prnt($string) {
echo $string;
}
function map($func, $arr) {
foreach($arr as $i) {
call_user_func($func, $i);
}
}
function linkScript($script) {
prnt("<script src='$script'></script>");
}
function linkStyle($style) {
prnt("<link rel='stylesheet' href='$style'/>");
}
function startPage($title, $script="", $imports=array(), $styles=array()) {
$pre_tags = array(
"<html>",
"<head>"
);
$post_tags = array(
"</head>",
"<body>"
);
map(prnt, $pre_tags);
prnt("<title>$title</title>");
map(linkScript, $IMPORTS);
map(linkScript, $imports);
map(linkStyle, $STYLES);
map(linkStyle, $styles);
map(prnt, $post_tags);
}
function genNav() {
$nav_links = array(
"Home"=>$HOME,
"Walkthroughs"=>$HOME . "/walkthroughs/",
"Dex"=>$HOME . "dex.php"
);
prnt("<div class='nav'>");
foreach ($nav_links as $key => $value) {
prnt("<a class='link' href='" . $value . "'/>" . $key . "</a>");
}
}
function endPage() {
$endTags = array(
"</body>",
"</html>"
);
}
?>
This is the error:
Warning: include(/base/startup.php): failed to open stream: No such file or directory in /var/www/html/index.php on line 2
Warning: include(): Failed opening '/base/startup.php' for inclusion (include_path='.:/usr/share/php') in /var/www/html/index.php on line 2
Test
Fatal error: Uncaught Error: Call to undefined function startPage() in /var/www/html/index.php:4 Stack trace: #0 {main} thrown in /var/www/html/index.php on line 4
Since you mentioned you are on a Linux machine, it looks like the issue is caused because of the / here. The / is considered the root directory of linux machine. So removing the / must most probably work:
<?php
include "base/startup.php"; // Try removing the slash.
echo "Test";
startPage("Home");
?>
Since you haven't enabled the display of errors, the issue would be, there's no /base in your system and it would have thrown an error, like Fatal: Include file not found., which is not displayed because of your configuration, instead it would have shown Error 500 silently.
Update
Along with the above error, after seeing your code, the next one is you need to quote the function names. So replace the stuff with:
map("prnt", $pre_tags);
prnt("<title>$title</title>");
map("linkScript", $IMPORTS);
map("linkScript", $imports);
map("linkStyle", $STYLES);
map("linkStyle", $styles);
map("prnt", $post_tags);
The next error is, you haven't included the global variables correctly inside the function. You need to use:
global $IMPORTS, $STYLES;
Now your code works as expected.
And finally finishing the endPage() function:
function endPage() {
$endTags = array(
"</body>",
"</html>"
);
foreach($endTags as $tag)
echo $tag;
}
I get an error in my php code when trying to get all the files from their directory, then creating html links for them and I don't understand why.
Here is the error:
Warning: printf(): Too few arguments in C:\Users\Ryan\Documents\Web Development\xampp\htdocs\muzik\player.php on line 59
Line 59 is:
printf("<li><a href='mp3/%s'>%s</a></li>", htmlentities($file->getBasename()));
Here is the code:
`echo '<ul id="playlist">';
foreach( new DirectoryIterator('mp3/') as $file) {
if( $file->isFile() === TRUE) {
printf("<li><a href='mp3/%s'>%s</a></li>", htmlentities($file->getBasename()));
}
}
echo '</ul>';`
You have two %s, so the printf expects 2 arguments and you only put one.
You may want to use this one :
$filename = htmlentities($file->getBasename();
printf("<li><a href='mp3/%s'>%s</a></li>", $filename, $filename);
I've the following PHP code that receives a file from an iOS app.
The information is received and for my debuggin $file is setted and has content in all its forms. The original value passed is btn-7.png and $file[0] = btn-7.
The function is processed and all images are copied to the system as I see them in the folder.... thus I dont know why i am getting this error.
The error appear in the first line available to the function that shows $_FILES[$file]
Does anyone have an idea why this is happening?
EDIT: As I said. No need to do var_dump because I can echo $file. Also I am debbugin from iOS console can't see non-JSON results, I only rely on PHP logs to know the actual error message.
EDIT2: as requested `var_dump(); (I am working from XCode, iOS dev console, not web browser)
ob_start();
var_dump($file);
$e = ob_get_contents();
ob_end_clean();
error_log($e, 0);
the result
[06-Jun-2013 17:58:26 UTC] string(9) "btn-7.png"`
the error
[06-Jun-2013 17:24:45 UTC] PHP Notice: Undefined offset: 0 in C:\xampp\htdocs\igym\classes\shareexercise.php on line 146
PHP
private function storeFile( $file )
{
$file = explode('.',$file);
$file = $file[0];
$msg['asd'] = $file;
echo json_encode($msg);
if( $_FILES[$file]["type"] !== "image/png" && $_FILES[$file]["size"] < 2048600 )
{
$error['error'] = 'There was a problem uploading your picture';
echo json_encode($error);
return 0;
}
if( move_uploaded_file( $_FILES[$file]['tmp_name'], IMGUPLOADDIR . '/' . $this->userID . '/' . $_FILES[$file]['name'] ) ) {
return true;
} else{
//$error['error'] = 'There was a problem uploading your picture';
//echo json_encode($error);
return false;
}
}
$_FILES is an associative array, not a numerical array:
From: php.net
$_FILES
An associative array of items uploaded to the current script via the HTTP POST method.
You should var_dump($_FILES) and see what the structure looks like. 0 doesn't exist because the index is the field name or some other string.
Aso: A tutorial on $_FILES
I'm trying to access the mime.types file from a model in codeIgniter.
function get_mime_type($filename, $mimePath = '../../assets'){
$fileext = substr(strrchr($filename, '.'), 1);
if (empty($fileext)) return (false);
$regex = "/^([\w\+\-\.\/]+)\s+(\w+\s)*($fileext\s)/i";
$lines = file("$mimePath/mime.types");
foreach($lines as $line){
if (substr($line, 0, 1) == '#') continue; // skip comments
$line = rtrim($line) . " ";
if (!preg_match($regex, $line, $matches)) continue; // no match to the extension
return ($matches[1]);
}
return (false); // no match at all
}
I've already tried the following when I call it:
$this->get_mime_type($filename, $mimePath = '../../assets');
$this->get_mime_type($filename, $mimePath = '/zenoir/assets');
$this->get_mime_type($filename, $mimePath = 'http://localhost:8080/zenoir/assets/mime.types');
But no luck. The mime.types file is in the assets folder and the model is inzenoir/application/models
The error was:
A PHP Error was encountered
Severity: Warning
Message: file(../../assets/mime.types) [function.file]: failed to open stream: No such file or directory
Filename: models/files.php
Line Number: 46
Why are you getting into so much trouble for the mime types, use mime_content_type() instead.
echo mime_content_type($mimePath.$filename);
And the problem with your code is the path issue. Use BASEPATH constant and traverse from there instead. You will omit all these sort of path issue.