Hi I've got an error in my Zend Framework project...
It raised:
Invalid controller specified (myweb)
Here is my apache error.log:
PHP Warning: Invalid argument supplied for foreach() in /var/www/myweb/application/layouts/scripts/layout.phtml on line 107
Here's my code in layout.phtml:
<?php foreach($this->category as $categories):?>
<li><div id="sidemenu"> �<?php echo $categories['categoriesName'];?></div></li>
<?php endforeach;?>
Can anybody help me?
The problem seems to be that for some reason your url is presenting myweb as the controller instead of what should be your controller.
My guess is the you are trying to use localhost to display your application so are presenting a url similar to http://localhost/myweb/...
While it is possible to use the localhost to view ZF applications it often becomes inconvenient as applications become more complex. I would suggest you use a vhost for anything more then a very simple application.
I'm pretty sure that when you resolve the url problem the php warning will likely fix itself.
It seems like the variable $this->category is not set in the Controller. You can do this by defining $this->view->category from your controller.
Mostly when using these controller generated variables in the layout script instead of the corresponding view script, you want to use the same data in every view. If this is the case, check this question: Sending variables to the layout in Zend Framework
This error come because your array $this->category is blank. if this is blank array or return nothing then how foreach loop will execute?
so first print this array and check.
Related
I am trying to create a simple web service that will give a result depending on parameters passed.
I would like to use file_get_contents but am having difficulties getting it to work. I have researched many of the other questions relating to the file_get_contents issues but none have been exactly the situation I seem to having.
I have a webpage:
example.com/xdirectory/index.php
I am attempting to get the value of the output of that page using:
file_get_contents(urlencode('https://www.example.com/xdirectory/index.php'));*
That does not work due to some issue with the https. Since the requesting page and the target are both on the same server I try again with a relative path:
file_get_contents(urlencode('../xdirectory/index.php'));
That does work and retrieves the html output of the page as expected.
Now if I try:
file_get_contents(urlencode('../xdirectory/index.php?id=100'));
The html output is (should be): Hello World.
The result retrieved by the command is blank. I check the error log and have an error:
[Fri Dec 04 12:22:54 2015] [error] [client 10.50.0.12] PHP Warning: file_get_contents(../xdirectory/index.php?id=100): failed to open stream: No such file or directory in /var/www/html/inventory/index.php on line 40, referer: https://www.example.com/inventory/index.php
The php.ini has these set:
allow_url_fopen, On local and On master
allow_url_include, On local and On master
Since I can get the content properly using only the url and NOT when using it with parameters I'm guessing that there is an issue with parameters and file_get_contents. I cannot find any notice against using parameters in the documentation so am at a loss and asking for your help.
Additional Notes:
I have tried this using urlencode and not using urlencode. Also, I am not trying to retrieve a file but dynamically created html output depending on parameters passed (just as much of the html output at index.php is dynamically created).
** There are several folks giving me all kind of good suggestions and it has been suggested that I must use the full blown absolute path. I just completed an experiment using file_get_contents to get http://www.duckduckgo.com, that worked, and then with a urlencoded parameter (http://www.duckduckgo.com/?q=php+is+cool)... that worked too.
It was when I tried the secure side of things, https://www.duckduckgo.com that it failed, and, with the same error message in the log as I have been receiving with my other queries.
So, now I have a refined question and I may need to update the question title to reflect it.
Does anyone know how to get a parameterized relative url to work with file_get_contents? (i.e. 'file_get_contents(urlencode('../xdirectory/index.php?id=' . urlencode('100'))); )
Unless you provide a full-blown absolute protocol://host/path-type url to file_get_contents, it WILL assume you're dealing with a local filesystem path.
That means your urlencode() version is wrongly doing
file_get_contents('..%2Fxdirectory%2Findex.php');
and you are HIGHLY unlikely to have a hidden file named ..%2Fetc....
call url with domain, try this
file_get_contents('https://www.example.com/inventory/index.php?id=100');
From reading your comments and additional notes, I think you don't want file_get_contents but you want include.
see How to execute and get content of a .php file in a variable?
Several of these answers give you useful pointers on what it looks like you're trying to achieve.
file_get_contents will return the contents of a file rather than the output of a file, unless it's a URL, but as you seem to have other issues with passing the URI absolutely....
So; you can construct something like:
$_GET['id'] = 100;
//this will pass the variable into the index.php file to use as if it was
// a GET value passed in the URI.
$output = include $_SERVER['DOCUMENT_ROOT']."/file/address/index.php";
unset($_GET['id']);
//$output holds the HTML code as a string,
The above feels hacky trying to incorporate $_GET values into the index.php page, but if you can edit the index.php page you can use plain PHP passed values and also get the output returned with a specific return $output; statement at the end of the included file.
It has been two years since I used PHP so I am just speculating about what I might try in your situation.
Instead of trying fetching the parsed file contents with arguments as a query string, I might try to set the variables directly within the php script and then include it (that is if the framework you use allows this).
To achive this I would use pattern:
ob_start -> set the variable, include the file that uses the variable -> ob_get_contents -> ob_end_clean
It is like opening your terminal and running the php file with arguments.
Anyway, I would not be surprised if there are better ways to achieve the same results. Happy hacking :o)
EDIT:
I like to emphasize that I am just speculating. I don't know if there are any security issues with this approach. You could of course ask and see if anyone knows here on stackoverflow.
EDIT2:
Hmm, scrap what I said last. I would check if you can use argv instead.
'argv' Array of arguments passed to the script. When the script is run on the command line, this gives C-style access to the command line parameters. When called via the GET method, this will contain the query string. http://php.net/manual/en/reserved.variables.server.php
Then you just call your php script locally but without the query mark indicator "?". This way you can use the php interpreter without the server.
This is likely to be the most general solution because you can also use argv for get requests if I am understanding the manual correctly.
I'm trying to modify the user's address right after registration.
When you create a new user, The address needs to be modified and a trailing string needs to be added, such as this : ####.
I've created an addon, added the path /controllers/frontend/profiles.post.php,
I've attached to the $mode == 'add' , That's where I'm stuck.
How can I know which variables are available to me, It seems there's no way to debug, var_dump or echo. nothing seems to work.
The file is executing because if I type some broken syntax the server returns 500 internal error,
So my main question :
How can you debug at all any CS-cart addon?
Patrick,
To find out what variables do you have you can use fn_print_r($_REQUEST)
where
fn_print_r - good looking cs-cart wrapper of print_r
Actually the variables from profiles.php are not available in profiles.post.php because these are different variable scopes.
So most probably the only variables you will have is global PHP like $_REQUEST $_SERVER etc..
Take a look at discussion or bestsellers add-on - they have products.post.php controllers which work absolutly the same ways a profiles.post.php and any other post controllers.
I've some strange issues with some php code.
if ($user->userType=='admin'){
If I use the above command, the php engine just stop interpreting and display the code in plain text on my browser. On the other hand if I use the below method it works:
if ($user['userType']=='admin'){
Again here also:
$_SESSION['currentUser']->id
If I use the above code it just displays the rest of code as plain text:
id); // fail user }else{ $authentication="failed"; $noAuthPresentation="loginForm"; }
Why this is happening? It's a big project and I don't want to change every line where there is an occurrence of ->.
Do I need to change some setting somewhere? I'm using WAMP server with php 5.5.12.
Any help ? Thanks!
You're mixing up types, user is an array, and not an object. Something in your php config is doing something strange to your error display it seems. Right click on the page that has the errors, and view source if possible.
Does login.php contain html and php code by chance?
I am just beginning to learn PHP, so I apologize if this is a basic question. I am using what I understand to be a CodeIgniter-like MVC framework (NOT CI though - a homegrown framework)
I am trying to pass two parameters to my index controller, each of which will display a different error message. The errors are generated from two individual post functions (i.e., if user's log in is incorrect and if email already exists at sign up).
public function index($error1=NULL, $error2=NULL) {
$this->template->content = View::instance('v_index_index');
$this->template->content->error1 = $error1;
$this->template->content->error2 = $error2;
echo $this->template;
}
What I am observing is that the only error displayed is the parameter that appears in the parentheses first (e.g., at index/index/error2 the error1 message is displayed). I've already tested the logic for determining the error type, so I know that is correct and believe it must have something to do with the above.
Any help is greatly appreciated!
I'm working on some code written by another developer and it is written in PHP. There is a line of code that is causing an error. I'm thinking that it is something you have to enable for PHP because it works just fine in another environment but doesn't work on the new environment and I haven't changed the code yet. The line is:
$structure->parts
$structure is a variable I've passed in but from a search online parts is a property. The error I'm getting says:
Undefined property: stdClass::$parts
Thanks for any help or ideas anyone might have.
Looks like parts doesn't exist there. Try running var_dump($structure) to get a better picture of what you're really dealing with.